PX
asked on
Calculate time diff
Hi,
My question is how can I write a function says like stop watch, time start, then stop, I want to get the time in mil seconds between that period.
thx
My question is how can I write a function says like stop watch, time start, then stop, I want to get the time in mil seconds between that period.
thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wonderful, quick response and exactly the answer as what I need, thx.
/* DIFFTIME.C: This program calculates the amount of time
* needed to do a floating-point multiply 10 million times.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main( void )
{
time_t start, finish;
long loop;
double result, elapsed_time;
printf( "Multiplying 2 floating point numbers 10 million times...\n" );
time( &start );
for( loop = 0; loop < 10000000; loop++ )
result = 3.63 * 5.27;
time( &finish );
elapsed_time = difftime( finish, start );
printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
}