BENCH_START: start the timerBENCH_LOG: log the time, increase iteration counterBENCH_MEAN(*m): get meanBENCH_MEAN_STD(*m,*s): get mean and stdevBENCH_LAST: get last logged timeBENCH_PRINT: print mean and stdevBENCH_PRINT_PERIOD(t): print every 't' iterationsBENCH_PERIOD(t): evaluate to true 't' iterationsBENCH_BENCH(nb_repeat, function): benchfunctionwith 'nb_repeat' repetitionBENCH_BENCH_PRINT(nb_repeat, print_period, function): benchfunctionand print every 'print_period' iterationsBENCH_RESET: reset iteration counterBENCH_INIT: init necessary variables
warning : mean and stdev are incorrect until the array is filled once (a star* is put at end of the print to warn of this case)
BENCH_LOG_SIZE: set the log size (default : 128)BENCH_PRECISION: set the time precision : s, ms, µs, ns (default : ms)BENCH_fd: set the output FILE* of fprintf (default : stdout)BENCH_PRINT_FORMAT: printf format for time (default : "%9.4lf")BENCH_NO_WARN_LOGSIZE: disable the star* at end of the print to warn that the array isn't filled.BENCH_CSV_PRINT: set the print output in csv format (mean, stdev, iterations)BENCH_NO_AUTO_INIT: disable auto init globals variables
math.h: sqrt(), defineBENCH_NO_SQRTto disable and get variance instead of stdev, or define your own sqrt in__BENCH_SQRT__time.h: clock_gettime()
#define BENCH_LOG_SIZE 256
#define BENCH_PRECISION µs
#define BENCH_NO_AUTO_INIT
#include "bench.h"
void func()
{
BENCH_INIT
for(int i = 0; i < nb_repeat; i++){
BENCH_START
function_to_bench();
BENCH_LOG
BENCH_PRINT_PERIOD(16)
}
// same as :
BENCH_BENCH_PRINT(nb_repeat, 16, function_to_bench());
BENCH_BENCH(nb_repeat,
reset_function_to_bench();
function_to_bench();
);
BENCH_PRINT
printf("%lf\n", BENCH_LAST);
double mean;
BENCH_MEAN(&mean);
}