Skip to content

Instantly share code, notes, and snippets.

@zhoukuo
Created July 13, 2012 03:05
Show Gist options
  • Save zhoukuo/3102430 to your computer and use it in GitHub Desktop.
Save zhoukuo/3102430 to your computer and use it in GitHub Desktop.
Calculate the execution time of millisecond
/* 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