gmio/benchs/commons/bench_tools.c

26 lines
561 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)
{
return (float)((clock() - start_tick) / (float)CLOCKS_PER_SEC);
}
void benchmark(
void (*func)(const char*), const char* title, int argc, char** argv)
2013-02-20 19:29:34 +08:00
{
2014-01-30 00:51:04 +08:00
const clock_t start_tick = clock();
int iarg;
2013-02-20 19:29:34 +08:00
if (func == NULL)
return;
2014-01-30 00:51:04 +08:00
printf("Bench %s ...\n", title);
2013-02-20 19:29:34 +08:00
for (iarg = 0; iarg < argc; ++iarg) {
2014-01-30 00:51:04 +08:00
printf(" Read file %s ...\n", argv[iarg]);
2013-02-20 19:29:34 +08:00
(*func)(argv[iarg]);
}
2014-01-30 00:51:04 +08:00
printf("\n %s exec time: %.2fs\n", title, elapsed_secs(start_tick));
2013-02-20 19:29:34 +08:00
}