Skip to content

Instantly share code, notes, and snippets.

@Ignavia-Snippets
Created December 28, 2013 14:31
Show Gist options
  • Save Ignavia-Snippets/8160050 to your computer and use it in GitHub Desktop.
Save Ignavia-Snippets/8160050 to your computer and use it in GitHub Desktop.
C: Timeit
#include <time.h>
#include <sys/time.h>
#include "timeit.h"
double timeit(void (*f)()) {
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
(*f)();
clock_gettime(CLOCK_MONOTONIC, &end);
return (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.0;
}
#ifndef TIMEIT
#define TIMEIT
double timeit(void (*f)());
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment