Created
December 28, 2013 14:31
-
-
Save Ignavia-Snippets/8160050 to your computer and use it in GitHub Desktop.
C: Timeit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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