Benchmark, how to?

Started by
4 comments, last by CtrlAltDelete 23 years, 11 months ago
what is the best way to benchmark small pieces of code? can someone point me to a freeware program or some sample benchmarking code? Thanks, Chuck
Advertisement
What IS benchmarking?



========================
Game project(s):
www.fiend.cjb.net
=======================Game project(s):www.fiend.cjb.net
A Benchmark is the method to see how long time a computer take to do a certain task. The most common heard, is monitoring the FPS-count for games and stuff. (FPS = Frames Per Second) This is for use when programmers try to optimize their code.
And now for the main Question:

An easy way of doing a benchmark over a bit of code, is something like this:


=======================================

unsigned long starttime = GetTickCount();
unsigned long endtime = starttime + 10000; //Set duration for 10 secs
unsigned long cycles = 0;
while (GetTickCount() < endtime)
{
/*
Place the code you want to monitor in here.
*/
cycles++;
}

float cycles_per_second = (float)cycles/10.0;
float cycleduration = 1/cycles_per_second;

=======================================

Now, cycleduration tells you how many seconds the code take to execute. For an easier way to look, multiply it by 1000 to view it in milliseconds.

Now, it''s up to you to optimize this code as much as you can. ie, to lower the value in cycleduration as much ass posible.
Good luck!

Electron

"Who need more than 640kb of RAM?" -Bill gates -89


--Electron"The truth can be changed simply by the way you accept it.""'General failure trying to read from file' - who is General Failure, and why is he reading my file??"
Michael Abrash (one of the authors of Quake) has a very accurate routine he calls the "Zen timer" that is available in most of his books. It''s great for profiling small sections of code. It probably is available on the net, although I don''t know where offhand.

Most compilers (except the standard edition of VC6, unfortunately) come with a profiler that will do what you want as well.

aig
aig
Electron I tried your method for benchmarking but the information its giving me seems to be too varied, by running the program more than once ive gotten differences between tests like 9.14ms to 9.11ms? is this normal?

Thanks, Chuck
If you would like to know more about that Zen-timer, check this out:
http://www.wdj.com/notgone/708art.htm

if it doesn''t seem interesting (dos), I can tell you how I do.

I use the debugger SoftICE from NuMega. (vxd based, will have total control of your system. You can even see it in graphics mode (ddraw or similar), usually) With that marvel, you can set a breakpoint at the call-instruction, and one after. When it first breaks, you just press ctrl+d, and it breaks on the instruction after the call. in the bottom right corner you now see how many milliseconds the execution of the call took you.

This topic is closed to new replies.

Advertisement