Testing the performance of a C++ app -
I'm trying to find a way to test how long a block of C ++ code is to run Takes up I'm using it to compare code with different algorithms and to compare under different languages, so ideally I need a time in seconds / milliseconds. In Java, I am using something like this:
long startTime = System.currentTimeMillis (); Ceremony (); Long Roast Time = System Courantime Milliseau (); Long-term time = stoptime - starttime; Is there a good way to get accurate time in C ++ (or should I use some other methods of benchmarking?)
Use the best counter available on your platform, back to time for portability. I am using QueryPerformanceCounter, but see comments in other answers.
General advice:
Inner loop must run at least 20 times the resolution to make your clock, resolve error & lt; 5% (Therefore, while using time (your internal loop should run at least 20 seconds)
Repeat these measures, to see if they are continuous
I Using an additional outer loop , ten times running, ignoring the fastest and least slow measurement for calculating average and deviation, deviation is accessible when comparing two implementations. Gets: If you have a 2.0 algorithm +/- 5, and another 2.2 +/- .5 , The difference in calling one of them "fast" is not important (maximum and minimum should still be displayed). Therefore, IMHO should have a valid performance measurement look like this:
10000 x 2.0 +/- 0.2 ms (minimum = 1.2, max = 12.6), 10 repetition If you know what you are doing, clean the cache And thread threads can make your measurement stronger.
However, this is the pifalls There is no more "stable" measurement, less realistic. Data and instruction will vary strongly with the implementation time on the basis of the cash situation. I'm lazy here, using Max = Price to judge the first run penalty, it will not be enough for some scenarios.
Comments
Post a Comment