Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is this the normal speed of QJSEngine?

Is this the normal speed of QJSEngine?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 713 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pablo_worker
    wrote on last edited by pablo_worker
    #1

    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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pablo_worker
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved