Created
July 12, 2012 12:51
-
-
Save snaga/3097909 to your computer and use it in GitHub Desktop.
test code to measure cost of gettimeofday() call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/time.h> | |
int | |
main(void) | |
{ | |
int i, j; | |
struct timeval s,e; | |
struct timeval t; | |
float avg; | |
gettimeofday(&s, NULL); | |
for (i=0 ; i<1000 ; i++) | |
{ | |
for (j=0 ; j<1000 ; j++) | |
{ | |
gettimeofday(&t, NULL); | |
} | |
} | |
gettimeofday(&e, NULL); | |
avg = (float)((e.tv_sec - s.tv_sec) * 1000 * 1000 + (e.tv_usec - s.tv_usec)) / 1000.0 / 1000.0; | |
printf("gettimeofday: avg %.2f usec.\n", avg); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment