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
|
|
|
}
|
|
|
|
|
2015-04-15 22:41:07 +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) {
|
2015-04-15 22:41:07 +08:00
|
|
|
printf(" File %s ...\n", argv[iarg]);
|
2015-03-30 22:43:26 +08:00
|
|
|
(*func)(argv[iarg]);
|
|
|
|
}
|
2015-04-15 22:41:07 +08:00
|
|
|
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
|
|
|
}
|