Skip to content

Instantly share code, notes, and snippets.

@zhoukuo
Created July 13, 2012 03:29
Show Gist options
  • Save zhoukuo/3102530 to your computer and use it in GitHub Desktop.
Save zhoukuo/3102530 to your computer and use it in GitHub Desktop.
Calculate the execution time of second
/* use time() to calculate the execution time in second */
#include <time.h>
long timecost(void (*dosomething)())
{
time_t start, end;
long cost;
start = time(NULL);
dosomething();
end = time(NULL);
cost = (int)difftime(end, start);
printf("cost time: %ld seconds", cost);
return cost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment