QJSEngine does not cache the compilation results if you just pass in plain
strings. I also don't think QScriptEngine can do this here (but I haven't
checked). QScriptEngine might be clever enough to automatically use the
interpreter rather than JIT-compiling such small expressions. You can set the
QV4_FORCE_INTERPRETER environment variable to force QJSEngine to use the
interpreter rather than the JIT.
In any case it's a waste to parse the expressions from strings over and over
and to not use the JIT. If you care about performance, you should try to parse
the expressions only once.
Uhm ... the secret here is that you keep a QScriptProgram as the m_expression
of your label item, which is basically a JS function compiled for QScript. So,
of course, if you take the source code from that and then recompile it for
QJSEngine on every iteration it will be slower than if you evaluate it straight
away in QScriptEngine. If you instead kept a QJSValue with the same expression
written as a JS function, QJSEngine would probably be much faster as
QScriptEngine would have to recompile on each iteration.
Interest mailing list