Possible Duplicate:
Windows C++ nanosecond timing?
I want to measure a function execution time. But I use old C++ (I mean I can't use chrono) and I am on windows. I cold not find any code snippet that does what I need. Please help.
Possible Duplicate:
Windows C++ nanosecond timing?
I want to measure a function execution time. But I use old C++ (I mean I can't use chrono) and I am on windows. I cold not find any code snippet that does what I need. Please help.
On Windows you have the option of using the high performance counter to get high resolution timing. This should be supported on even very old Windows installations and old compilers.
take a look at QueryPerformanceCounter Elapsed time can be obtained in ticks and you know the number of ticks per second. It may not be reliable over large intervals because the CPU speed may change.
You can use the QueryPerformanceCounter
LARGE_INTEGER liFrequency = {0};
// Get the Frequency
if(QueryPerformanceFrequency(&liFrequency))
{
// Start Timing
LARGE_INTEGER liStart = {0};
if(QueryPerformanceCounter(&liStart))
{
// Do Stuff
// Get Time spent...
LARGE_INTEGER liStop = {0};
if(QueryPerformanceCounter(&liStop))
{
LONGLONG llMilliseconds = (LONGLONG)((liStop.QuadPart - liStart.QuadPart) * 1000.0 / liFrequency.QuadPart);
printf("time ellapsed ms:%lld\n", llMilliseconds);
}
}
}