Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] How to set the type for QElapsedTimer?

    General and Desktop
    1
    4
    2394
    Loading More Posts
    • 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.
    • ?
      Guest last edited by

      I need to profile a few methods that are very fast, and by default QElapsedTimer for me works in msec, causing it always to return 0.

      @Nonsense conversion took 0
      Tedious operations took 0 @

      How can I change the type of the timer to lets say ticks, so I can actually do some profiling and optimizations?

      1 Reply Last reply Reply Quote 0
      • K
        koahnig last edited by

        You may also output in "nsec":https://qt-project.org/doc/qt-4.8/qelapsedtimer.html#nsecsElapsed
        I guess output in ticks is not supported because it would be platform dependent.
        Probably you should post a part of the code doing the output.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply Reply Quote 0
        • ?
          Guest last edited by

          I am using qDebug() for the output, which I know is kind of wrong, especially since it only works in debug mode which is slower. Anyway, the nsecsElapsed() method totally did the trick for me, now I actually have numbers to work with:

          @Nonsense conversion took 57662
          Tedious operations took 816581 @

          EDIT: Turns out an if (!) statement takes more than generating three random values, 10 arithmetic operations and two getter and setter methods. I wanted to see if it will be faster to skip pixels with 0% visibility, turns out checking for 0% visibility is a little more expensive than processing everything.

          @ if (!(test.pixel(iX, iY) == 0xFF))
          test2.setPixel(iX, iY, qRgba(255 - (qrand() % 100), 0 + (qrand() % 100), 0 + (qrand() % 100), qAbs((int)test.pixel(iX, iY)-255)));@

          With the if statement skipping all non-visible pixels (about 80% of the image) takes about 820000 nsec, without the if statement, processing everything takes about 760000 nsec, which is a good ~8% on average.

          1 Reply Last reply Reply Quote 0
          • K
            koahnig last edited by

            Thanks for feedback. It is always good to know that something worked out ;-) You might want to change the title and add [Solved].

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post