Never been to DZone Snippets before?

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

About this user

Alexandru Scvortov

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Time it - C

This function runs another function, given as a parameter, a certain number of times and returns the number of cycles needed to complete.

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  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS