Last active
September 6, 2022 14:40
-
-
Save 3outeille/a9d7ddcbc9797ad5d04bae3812163160 to your computer and use it in GitHub Desktop.
gsoc gist
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
struct BenchWrapper | |
{ | |
size_t nb_fct_call; | |
size_t iter_per_fct; | |
// Define function arguments here | |
int (*func)(const OVSEI *sei, OVFrame **frame); | |
}; | |
void bench_decorator(struct BenchWrapper bw, char* name, const OVSEI *sei, OVFrame **frame) | |
{ | |
volatile int dummy; | |
double total_avg_time = 0; | |
for (size_t i = 0; i < bw.nb_fct_call; ++i) | |
{ | |
double avg_time = 0; | |
for (size_t j = 0; j < bw.iter_per_fct; ++j) | |
{ | |
double t1 = clock(); | |
volatile const int r = bw.func(sei, frame); | |
double t2 = clock(); | |
dummy = r; | |
double dt = (t2 - t1) * 1000 / CLOCKS_PER_SEC; // millisecond | |
avg_time += dt; | |
} | |
avg_time /= (double)bw.iter_per_fct; | |
total_avg_time += avg_time; | |
} | |
total_avg_time /= (double)bw.nb_fct_call; | |
printf("%-20s: %f ms (average time / %lu calls of %lu iteration each)]\n", | |
name, | |
total_avg_time, | |
bw.nb_fct_call, | |
bw.iter_per_fct); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment