Over a million developers have joined DZone.

Time It - C

DZone's Guide to

Time It - C

Free Resource
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.


typedef void(*FN)();

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

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

  return clock() - start;


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}