Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is this the normal speed of QJSEngine?



  • Hi!

    I am tinkering with the QJSEngine. As far as I understand, a QJSEngine instance will evaluate a JavaScript code passed to it. However, I am concerned about the computation speed of QJSEngine, it seems very slow.

    My computer spends around 3-4 seconds computing this simple JavaScript code, is this normal?:

    var X = [];
    for (var i=0 ; i < 934600 ; ++i )
    {
       X[i] = i;
    }
    X[120]
    

    This is a simple code snippet of how I use QJSEngine.
    Let's suppose that we have a button in the GUI, and when the button is pressed the following code is executed (it needs 4 seconds before the result is printed in the debug console):

    void MainWindow::slot_ExecuteScript()
    {
       QJSEngine myEngine;
       QString myScript = "var X = [];";
       myScript.append("for (var i=0 ; i < 934600 ; ++i ){X[i]=i;}");
       myScript.append("X[140]");
       QJSValue myValue = myEngine.evaluate(myScript);
       if(myValue.isError())
       {
          qDebug() << myValue.property("message").toString();
       }
       else
       {
          qDebug() << myValue.toString();
       }
    }
    

    Tested with Qt Creator 4.0.1. With Qt 5.7 MSVC2013 64 bits.


  • Moderators

    @pablo_worker On Ubuntu 14.04 with Qt 5.6 and Qt 5.7 64 bits it is between 400 to 500 ms.



  • Thank you!
    The problem was that I was trying that in debug mode.
    I have compiled again in Release mode and now its much faster!

    Times (measured with QElapsedTimer)
    In Debug mode: 3001 - 2999 ms.
    In Release mode: 256 - 296 ms

    10 times slower!


Log in to reply