// test sleep() and msec() timing // #include #include // unsigned int sleep(unsigned int seconds) #include // int gettimeofday(struct timeval *tv, struct timezone *tz) double msec( void) // time in milliseconds { struct timeval tv; if( gettimeofday(&tv,0) < 0) { perror("gettimeofday"); return 0; } return tv.tv_sec*1000.0 + tv.tv_usec/1000.0; } int main( void) { printf( "sleeping for 1 second...\n"); double t0 = msec(); sleep(1); double t1 = msec(); printf( "elapsed time %g msec\n", t1-t0); return 0; } /* sample output: sleeping for 1 second... elapsed time 1000.33 msec */