QScriptEngine: which expression is faster ?
I'm making a scriptable application, and I'm wondering which kind of expression is faster:
engine.evaluate("object1.property1").toString(); engine.evaluate("object1.property2").toString(); engine.evaluate("object1.property3").toString();
QScriptValue object1 = engine.property("object1"); object1.property("property1").toString(); object1.property("property2").toString(); object1.property("property3").toString();
Is the second method faster (I 'save' object1 and I'm hoping that property() does not invoke the interpreter). ? I'm I right ?
Hi. Why don't you just measure and see what's faster?
Possible answer: it's the same.
Either property() invokes the interpreter or object1 is "changed" everytime the underlying script changes it.
Because if I do:
// let's assume object1 is an array QScriptValue object1= engine.property("object1");
and I do:
qDebug() << object1.toVariant();
The object1 will contains the latest changes, even if it has been changes outside C++.
This makes me believe that QScriptValue objects are tied to the underlying JS objects. Any change in the JS will immediately be seen in C++.