gmio/benchs/commons/bench_tools.c

30 lines
707 B
C
Raw Normal View History

2013-02-20 19:29:34 +08:00
#include "bench_tools.h"
#include <stdio.h>
float elapsed_secs(clock_t start_tick)
{
2015-03-30 22:43:26 +08:00
return (float)((clock() - start_tick) / (float)CLOCKS_PER_SEC);
2013-02-20 19:29:34 +08:00
}
void benchmark_list(bench_file_func_t func, const char* title, int argc, char **argv)
2013-02-20 19:29:34 +08:00
{
2015-03-30 22:43:26 +08:00
const clock_t start_tick = clock();
int iarg;
2014-01-30 00:51:04 +08:00
2015-03-30 22:43:26 +08:00
if (func == NULL)
return;
2013-02-20 19:29:34 +08:00
2015-03-30 22:43:26 +08:00
printf("Bench %s ...\n", title);
for (iarg = 0; iarg < argc; ++iarg) {
printf(" File %s ...\n", argv[iarg]);
2015-03-30 22:43:26 +08:00
(*func)(argv[iarg]);
}
printf(" exec time: %.2fs\n\n", elapsed_secs(start_tick));
}
void benchmark(bench_file_func_t func, const char *title, const char* filepath)
{
benchmark_list(func, title, 1, (char**)&filepath);
2013-02-20 19:29:34 +08:00
}