Skip to content

Instantly share code, notes, and snippets.

@zhoukuo
Created July 13, 2012 03:21
Show Gist options
  • Save zhoukuo/3102485 to your computer and use it in GitHub Desktop.
Save zhoukuo/3102485 to your computer and use it in GitHub Desktop.
Calculate the execution time of microseconds
/* use gettimeofday() to calculate the execution time in microseconds */
#include <sys/time.h>
long timecost(void (*dosomething)())
{
struct timeval start, end;
long cost;
gettimeofday(&start, NULL);
dosomething();
gettimeofday(&end, NULL);
cost = end.tv_usec - start.tv_usec;
printf("cost time: %ld us", cost);
return cost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment