Created
July 13, 2012 03:05
-
-
Save zhoukuo/3102430 to your computer and use it in GitHub Desktop.
Calculate the execution time of millisecond
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
/* use ftime() to calculate the execution time of millisecond */ | |
#include <sys/timeb.h> | |
long timecost(void (*dosomething)()) | |
{ | |
struct timeb begin, end; | |
long cost; | |
ftime(&begin); | |
dosomething(); | |
ftime(&end); | |
cost = (long)(end.time - begin.time)*1000 + (end.millitm - begin.millitm); | |
printf("cost time: %ld ms\n", cost); | |
return cost; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment