[SOLVED] How to set the type for QElapsedTimer?
-
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?
-
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. -
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.
-
Thanks for feedback. It is always good to know that something worked out ;-) You might want to change the title and add [Solved].