Time it - C
Useful for timing short snippets of code.
1 2 #include <time.h> 3 4 typedef void(*FN)(); 5 6 double timeit(FN f, int n) { 7 clock_t start = clock(); 8 9 int i = 0; 10 for (; i < n; ++i) 11 f(); 12 13 return clock() - start; 14 }
DZone Snippets > scvalex > timer
13374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 #include <time.h> 3 4 typedef void(*FN)(); 5 6 double timeit(FN f, int n) { 7 clock_t start = clock(); 8 9 int i = 0; 10 for (; i < n; ++i) 11 f(); 12 13 return clock() - start; 14 }