Last active
June 15, 2020 15:06
-
-
Save nick87720z/5b84e7a09a3df7c85bf12b29f2606a56 to your computer and use it in GitHub Desktop.
Inline counter wrapper
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 <stdio.h> | |
/* In-place counter wrapper code */ | |
#define begin_perf(time, idle_time, name) { \ | |
clock_t tstart = clock (); \ | |
clock_t tcur = 0; \ | |
guint64 counter = 0; \ | |
int sec = -(idle_time); \ | |
putchar ('\n'); \ | |
while (1) \ | |
{ \ | |
counter++; \ | |
tcur = clock (); \ | |
if (time == -1) \ | |
{ \ | |
printf ("clock doesn't work\n"); \ | |
break; \ | |
} \ | |
if ( tcur - tstart >= CLOCKS_PER_SEC ) \ | |
{ \ | |
sec++; \ | |
tstart += CLOCKS_PER_SEC; \ | |
if (sec <= 0) \ | |
{ \ | |
counter = 0; \ | |
continue; \ | |
} \ | |
printf ("\r%s: %lu loops ", (name), counter / sec); \ | |
fflush (stdout); \ | |
if (sec >= (time)) \ | |
break; \ | |
} | |
#define end_perf \ | |
} \ | |
putchar ('\n'); \ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment