Skip to content

Instantly share code, notes, and snippets.

@snaga
Created July 12, 2012 12:51
Show Gist options
  • Save snaga/3097909 to your computer and use it in GitHub Desktop.
Save snaga/3097909 to your computer and use it in GitHub Desktop.
test code to measure cost of gettimeofday() call.
#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