@
tool2d [admin@iZt4ngr7j75qbzgg9ilsifZ c]$ cat duff2.c
#include <sys/time.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
long count = 2147483640;
volatile long i = 0;
do {
++i;
} while (--count);
gettimeofday(&end_time, NULL);
int total_time = 1000000 * (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec);
printf("%d us", total_time);
printf("\n");
printf("%.3f ms", (double) total_time / 1000);
printf("\n");
printf("%l", i);
return 0;
}
[admin@iZt4ngr7j75qbzgg9ilsifZ c]$ gcc duff2.c && ./a.out
4621705 us
4621.705 ms