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

Time it - C (See related posts)

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.

#include <time.h>

typedef void(*FN)();

double timeit(FN f, int n) {
  clock_t start = clock();

  int i = 0;
  for (; i < n; ++i)
    f();

  return clock() - start;
}

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts