PDA

View Full Version : QJSEngine vs QScriptEngine speed



ivareske
20th May 2015, 09:55
As far as I understood the QScriptEngine class is being replaced by the QJSEngine class. I also read QJSEngine should be more efficient. I however experience the opposite, the execution of the script function I have becomes about 10 times slower with QJSEngine compared to QScriptEngine, and a factor of 100 slower compared to using QScriptEngine together with QScriptProgram (I tested calling the function below 1000 times in a loop, got about 3000, 300 and 30 msec). My function looks like this, it calculates the gas density based on a user-specified function of pressure and temperature:

double computeScriptFunction(const double &p, const double &T, const QString &program)const{
static ScriptEngine e;
static ScriptValue globObj;
static bool isInit=false;
if(!isInit){
globObj = e.globalObject();
isInit = true;
}
globObj.setProperty("p",p);
globObj.setProperty("T",T);
ScriptValue val = e.evaluate(program);
return val.toNumber();
}

ScriptEngine and ScriptValue are here typedefs for QJSEngine/QScriptEngine and QJSValue/QScriptValue depending on what I want to use. The code I use when using QScriptProgram is identical except that the function input is a QScriptProgram and not a QString.

Does anyone have any experience with the speed of QJSEngine vs QScriptEngine?
Does there exist anything similar to QScriptProgram for QJSEngine?

Regards, Ivar