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. QElapsedTimer possibly broken?

QElapsedTimer possibly broken?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k 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.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    I've been profiling an interpreter I am implementing and I used QElapsedTimer and the results were just not making any sense. Then I noticed shortening the program had little effect on the measurement with QElapsedTimer, so I switched to profiling with raw processor clocks, which confirmed QElapsedTimer numbers were way off for some reason.

    Qt 4.8 with GCC on windows 7

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sidewinder
      wrote on last edited by
      #2

      How did you use it? Show us some code please.
      Also, consider using "QTestLib":http://qt-project.org/doc/qt-4.8/qtestlib-manual.html and "QBENCHMARK":http://qt-project.org/doc/qt-4.8/qtest.html#QBENCHMARK macro.

      "Never memorize what you can look up in books."
      Albert Einstein

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        Well, I wasn't doing anything extraordinary, if that's what you mean...

        @QElapsedTimer timer;
        .
        .
        timer.restart();
        //do some work
        cout << "work took " << timer.nsecelapsed();@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sidewinder
          wrote on last edited by
          #4

          Weird. I just checked in different scenarios and modifying code definitely influences QElapsedTimer results which seems quite accurate... Have you tried simple Sleep() tests?
          I'm on windows 7, Qt 4.8.2, GCC 4.6.2

          "Never memorize what you can look up in books."
          Albert Einstein

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            The timer is sometimes accurate, sometimes not. I was profiling the performance of this switch:

            @ static void* table[] = {
            &&do_add,
            &&do_sub,
            &&do_mul,
            &&do_div,
            &&do_end,
            &&do_err,
            &&do_fin};

            #define jump() goto *table[op[c++]]

                jump();
            

            do_add:
            add(in1[c], in2[c], out[c]); jump();
            do_sub:
            sub(in1[c], in2[c], out[c]); jump();
            do_mul:
            mul(in1[c], in2[c], out[c]); jump();
            do_div:
            div(in1[c], in2[c], out[c]); jump();
            do_end:
            // cout << "end of program" << endl;
            goto *table[6];
            do_err:
            cout << "ERROR!!!" << endl; goto *table[6];
            do_fin:@

            The switch goes through a byte array (op) symbolizing bytecode, and what I noticed is modifying the length of the array all the way from 100 million to 100 always returned a varying but still astronomically high nsecsElapsed().

            I profiled against the same workload written and compiled to native machine code, and instead of getting a constant ratio between interpreted and native performance as program length varied, the difference got preposterously more pronounced as program got shorter. It was then when I suspected QElapsedTimer might be the culprit, switched to using the clock() function from the standard C library and got consistent performance between interpreted and native as program length varied.

            Timing the switch was broken each time, whereas timing the native code was adequate.

            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