Advertisement

Benchmarking a function ?

Started by August 19, 2001 08:53 PM
4 comments, last by ogracian 23 years, 6 months ago
Hello I really appreciate if anyone could explainme how benchmark a function performance?, I mean how can I test the optimizations done in one function? Thanks in advance! Oscar
That''s what a profiler is for. Visual C++ Professional comes with one, but there are several other profilers out there that you can buy as well.
Advertisement
Thanks for the help!

I will use the Visual C++ profiler.

Best Regards!
For newbies who may not have thought of this...
To simply time how long a function takes to execute (in milliseconds):

------------------------------------------------------------
int StartTime;
int EndTime;
int ExectutionTime;

StartTime = GetTickCount ();
SlowPokeFunction();
EndTime = GetTickCount();

ExecutionTime = EndTime - StartTime;
------------------------------------------------------------

-Cyex
Yeah, that would work cyex, but for that situation you would be better off using a high-res performance timer to get better accuracy (just make sure you check to see if the user has one first). If you have a profiler though, it isn''t worth the bother setting up timers on every function you want to test.
I''ve got the book "Game Programming Gems" (good book) and there''s a section in it about writing an in program compiler, I''ve haven''t had a proper read of the section but I think the idea is you do some thing like

pProfile->function_start("name of function");

at the top of a function, then some thing like

pProfiler->function_end("name of function");

then when the program exits you get the results dumped to file in a sort of tree which tell you the maximum, minimum and average time taken in each function.

It''s not the hardest thing in the world to do, you can probably write one from the description I just gave, but like MC says use a high-res performance timer, I think the function you need is called QueryPerformanceTimer() (under windoze anyway),

NOTE: you will need to determine the frequency of the performance timer first first.

PS: if its not QueryPerformanceTimer try QueryPerformanceCounter - I can''t remember its name

This topic is closed to new replies.

Advertisement