This item was added on: 2003/03/22
The best way to time the performance of a program is to use a profiler, it is the most accurate and gives more useful output than a simple minded timing. But if you don't have access to a profiler, you can get some of its functionality by way of the time functions in <time.h>
or <ctime>
:
#include <stdio.h>
#include <time.h>
int main ( void )
{
clock_t start, end;
start = clock();
printf ( "Please wait a few moments and hit return\n" );
getchar();
end = clock();
printf ( "The interval was: %f seconds\n",
(double)( end - start ) / (double)CLOCKS_PER_SEC );
return 0;
}
Credit: Prelude