PDA

View Full Version : How to test the performance of your code?



chronozphere
01-05-2010, 03:34 PM
Hey PGD-friends, 8)

I have a piece of code here which I want to test. I'm not sure how though. ???

I have the impression that QueryPerformanceCounter() is a bit unstable (Because of the CPU stepping times that change). GetTickCount() on the other hand is not accurate enough.
I have an important piece of code for my game, which is going to be called multiple times a frame. So the execution time must be well under 1ms. Also, I want to make some alterations to the algorithm and see if it improves it's performance.

Any ideas how to do some reliable tests?

Thanks :)

phibermon
01-05-2010, 05:54 PM
I'm a business analyst by trade and I say increase your sample space.

That is, measure iterations over a longer period of time and either track CPU usage along with that time (allows you to pick a sample space with the minimum of CPU usage spikes) or do your best to ensure the thread is not interrupted excessively by the OS. (set the thread to real-time priority if you must)

Then, count the loops performed in say, 30 seconds then finally divide it down so you know the average processing time in MS for a single pass.

That average will become increasingly more accurate the more time you sample, as long as you've taken care to avoid excessive thread interruption, you'll find that figure to be suitable for your purposes.

arthurprs
02-05-2010, 11:48 PM
I don't know anything better than QueryPerformanceCounter :no:

Andreaz
03-05-2010, 05:03 AM
Where do you got the information about QueryPerformanceCounter being unstable?

To my knowledge QueryPerformanceCounter increases one each cpu cycle and QueryPerformanceFrequency usually returns you're cpu clock speed.

This should, afaik be very accurate as it gets as the cpu cycle is determined my some kind of quartz crystal witch has a very well defined oscillation time. I could be wrong through ;)

chronozphere
03-05-2010, 08:46 AM
I vaguely recall an article on QueryPerformanceCounter. And you are right about the frequency. If you keep updating that too, it "should" work correctly. There might be other reasons to "not use it", but I have to dig up that article. :)

AthenaOfDelphi
03-05-2010, 09:29 AM
If you want to get a bit deeper, you could invest in a code profiler like ProDelphi (http://www.prodelphi.de/indexpd.htm). I've used this quite a bit to optimise my web server software.

igel457
03-05-2010, 08:40 PM
The free alternative is using FPC and more or less easily profiling your application using valgrind.

jdarling
03-05-2010, 09:31 PM
I've had some pretty good luck with http://wiki.lazarus.freepascal.org/EpikTimer and using its sampling routines. Granted its a bit out of date (2006) but still works like a charm.

- Jeremy

paul_nicholls
04-05-2010, 05:22 AM
There is always the free Delphi profiler here:

http://delphitools.info/samplingprofiler/

cheers,
Paul