Calculating the execution time of a Program
-
Hello all, Will u give me way to claculate the execution time of a program(or between any statemants) in Microseconds (in VC++). I was able to get the execution time in Milliseconds anyway by using GetTickCount API. Are there any way to calaculate in Microseconds(programmatically!!!!!!). Problem in above said API is that,when the range goes below 0 (in ms), the Microsecond value is not displayed( but rather 0 is Displayed). I am in immediate need!! Thanks in advace.. :rose: Rane
-
Hello all, Will u give me way to claculate the execution time of a program(or between any statemants) in Microseconds (in VC++). I was able to get the execution time in Milliseconds anyway by using GetTickCount API. Are there any way to calaculate in Microseconds(programmatically!!!!!!). Problem in above said API is that,when the range goes below 0 (in ms), the Microsecond value is not displayed( but rather 0 is Displayed). I am in immediate need!! Thanks in advace.. :rose: Rane
Rane wrote:
Are there any way to calaculate in Microseconds(programmatically!!!!!!).
Yes, just multiply milliseconds by 1000. ;)
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Rane wrote:
Are there any way to calaculate in Microseconds(programmatically!!!!!!).
Yes, just multiply milliseconds by 1000. ;)
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
But I was not able to get values below 0 ms.(in microseconds range).If it is more ur ans is correct. For Ex: Try finding the execution time of 2 or 3 statements, u will get the answer as 0 ms. Isn't it. Then what is the time spent in executing those statements!!!. Thanks 4 ur Reply:rose: Rane
-
Hello all, Will u give me way to claculate the execution time of a program(or between any statemants) in Microseconds (in VC++). I was able to get the execution time in Milliseconds anyway by using GetTickCount API. Are there any way to calaculate in Microseconds(programmatically!!!!!!). Problem in above said API is that,when the range goes below 0 (in ms), the Microsecond value is not displayed( but rather 0 is Displayed). I am in immediate need!! Thanks in advace.. :rose: Rane
With a little work, you can get there. You'll need to use the function QueryPerformanceCounter()[^] along with QueryPerformanceFrequency()[^]. Before you start though, you should really read an excellent article here on CP by Joseph Newcomer: Time is the Simplest Thing... to make sure you have a grasp of the many things that can ( and will! ) throw off your timing measurements in the Windows environment. Regards, Dan Remember kids, we're trained professionals.
Don't try this at home! -
But I was not able to get values below 0 ms.(in microseconds range).If it is more ur ans is correct. For Ex: Try finding the execution time of 2 or 3 statements, u will get the answer as 0 ms. Isn't it. Then what is the time spent in executing those statements!!!. Thanks 4 ur Reply:rose: Rane
Read here to make sure you know what you are asking (and why it may not be available).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Hello all, Will u give me way to claculate the execution time of a program(or between any statemants) in Microseconds (in VC++). I was able to get the execution time in Milliseconds anyway by using GetTickCount API. Are there any way to calaculate in Microseconds(programmatically!!!!!!). Problem in above said API is that,when the range goes below 0 (in ms), the Microsecond value is not displayed( but rather 0 is Displayed). I am in immediate need!! Thanks in advace.. :rose: Rane
-
With a little work, you can get there. You'll need to use the function QueryPerformanceCounter()[^] along with QueryPerformanceFrequency()[^]. Before you start though, you should really read an excellent article here on CP by Joseph Newcomer: Time is the Simplest Thing... to make sure you have a grasp of the many things that can ( and will! ) throw off your timing measurements in the Windows environment. Regards, Dan Remember kids, we're trained professionals.
Don't try this at home! -
With a little work, you can get there. You'll need to use the function QueryPerformanceCounter()[^] along with QueryPerformanceFrequency()[^]. Before you start though, you should really read an excellent article here on CP by Joseph Newcomer: Time is the Simplest Thing... to make sure you have a grasp of the many things that can ( and will! ) throw off your timing measurements in the Windows environment. Regards, Dan Remember kids, we're trained professionals.
Don't try this at home! -
I have tried using the APIs which u have mentioned. It is giving the value in mSec .Is it a correct value or a blurred one? Thanks in Advance. :rose:
Here is a simple console application (developed under VC++ 6 ). It measures the time it takes a 'printf()' statement to execute and displays that time in microseconds.
#include <windows.h>
#include <stdio.h>int main(int argc, char* argv[])
{
// retrieve frequency of high-resolution performance counter
// exit program if counter is not available on this systemLARGE\_INTEGER perfFreq; if( !::QueryPerformanceFrequency(&perfFreq) ) { printf( "High Performance Counter not available!\\n" ); return -1; } printf( "Performance Counter Frequency: %I64d ticks / second\\n", perfFreq.QuadPart ); printf( " or %e microseconds / tick \\n\\n", 1.0e6 / perfFreq.QuadPart ); // determine time needed to execute 'printf()' LARGE\_INTEGER perfStartTime; LARGE\_INTEGER perfEndTime; ::QueryPerformanceCounter( &perfStartTime ); printf( "\\n(\* This is the statement that I am timing \*)\\n\\n\\n" ); ::QueryPerformanceCounter( &perfEndTime ); // report measured execution time printf( "Measured Time: %I64d ticks\\n", perfEndTime.QuadPart - perfStartTime.QuadPart ); printf( " or %f microseconds\\n\\n\\n", 1.0e6 \* ( perfEndTime.QuadPart - perfStartTime.QuadPart ) / perfFreq.QuadPart ); return 0;
}
On my machine the output produced is:
Performance Counter Frequency: 3579545 ticks / second
or 2.793651e-001 microseconds / tick(* This is the statement that I am timing *)
Measured Time: 80 ticks
or 22.349209 microsecondsDan Remember kids, we're trained professionals.
Don't try this at home! -
Here is a simple console application (developed under VC++ 6 ). It measures the time it takes a 'printf()' statement to execute and displays that time in microseconds.
#include <windows.h>
#include <stdio.h>int main(int argc, char* argv[])
{
// retrieve frequency of high-resolution performance counter
// exit program if counter is not available on this systemLARGE\_INTEGER perfFreq; if( !::QueryPerformanceFrequency(&perfFreq) ) { printf( "High Performance Counter not available!\\n" ); return -1; } printf( "Performance Counter Frequency: %I64d ticks / second\\n", perfFreq.QuadPart ); printf( " or %e microseconds / tick \\n\\n", 1.0e6 / perfFreq.QuadPart ); // determine time needed to execute 'printf()' LARGE\_INTEGER perfStartTime; LARGE\_INTEGER perfEndTime; ::QueryPerformanceCounter( &perfStartTime ); printf( "\\n(\* This is the statement that I am timing \*)\\n\\n\\n" ); ::QueryPerformanceCounter( &perfEndTime ); // report measured execution time printf( "Measured Time: %I64d ticks\\n", perfEndTime.QuadPart - perfStartTime.QuadPart ); printf( " or %f microseconds\\n\\n\\n", 1.0e6 \* ( perfEndTime.QuadPart - perfStartTime.QuadPart ) / perfFreq.QuadPart ); return 0;
}
On my machine the output produced is:
Performance Counter Frequency: 3579545 ticks / second
or 2.793651e-001 microseconds / tick(* This is the statement that I am timing *)
Measured Time: 80 ticks
or 22.349209 microsecondsDan Remember kids, we're trained professionals.
Don't try this at home!