0

I'm trying to time multiple functions using GetTickCount() separately in a very large piece of code to find where exactly the bottlenecks are. I can successfully time the whole piece of code. What I'm struggling to work out is where do I add the timing function to measure time for each individual function. Do I insert the timer when the functions are declared or when they are defined or inside the main () where they are being called. Any help would be really appreciated. Thank you.

Jason Braucht
  • 2,358
  • 19
  • 31
Forcom
  • 1

1 Answers1

1

You time them when they are called at runtime, eg:

int main(int argc, char** argv)
{
    ...
    DWORD start = GetTickCount();
    CallAFunction();
    DWORD end = GetTickCount();
    DWORD elapsed = (end >= start) ? (end - start) : ((MAXDWORD - start) + end);
    ...
}

A better way to measure code timings is to use a profiler instead of writing logic in the code itself. A profiler hooks into the runtime process and inserts its own code inside the functions themselves. Then it can track not only how long the functions take to run, but also how many times they are called, what functions call which functions, log call stacks, etc. All without writing any extra code.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770