Platinum Partner

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.


#include 

typedef void(*FN)();

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

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

  return clock() - start;
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}