Created
January 29, 2018 01:47
-
-
Save EvanTheB/330b187bdbbd35840117da81378f44f4 to your computer and use it in GitHub Desktop.
helper macro for timing a function in c - beware of optimisation
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
#define TIMEIT(F, N, REPS) \ | |
{\ | |
clock_t start = clock();\ | |
for (int i = 0; i < N; ++i)\ | |
{\ | |
}\ | |
clock_t diff_loop = clock() - start;\ | |
double results[REPS];\ | |
for (int i = 0; i < REPS; ++i)\ | |
{\ | |
clock_t start = clock();\ | |
for (int j = 0; j < N; ++j)\ | |
{\ | |
F;\ | |
}\ | |
clock_t diff = clock() - start - diff_loop;\ | |
results[i] = ((double)diff) / CLOCKS_PER_SEC;\ | |
}\ | |
res = meana(results, REPS);\ | |
if (maxa(results, REPS) - mina(results, REPS) > 0.1 * res)\ | |
{\ | |
fprintf(stderr, "spread large\n");\ | |
}\ | |
}\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment