Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CtrlAltDelete

Benchmark, how to?

This topic is 6921 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!