Created
July 13, 2012 03:21
-
-
Save zhoukuo/3102485 to your computer and use it in GitHub Desktop.
Calculate the execution time of microseconds
This file contains hidden or 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
/* 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