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. [SOLVED] How to set the type for QElapsedTimer?
QtWS25 Last Chance

[SOLVED] How to set the type for QElapsedTimer?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 2.6k Views
  • 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    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
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        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
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          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
          0

          • Login

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