Add option to print only the best or only the average

This commit is contained in:
Patrick Pelissier committed 2019-12-15 10:12:38 +01:00
1 parent e99735d2b6
commit 03b6146ef0
1 file changed
+21 -10
+21 -10
View File
@@ -47,7 +47,7 @@ struct parse_opt_s {
int test_function;
double from, to, step, grow;
unsigned repeat;
bool graph;
bool graph, best, average;
};
static void
@@ -61,6 +61,8 @@ parse_config(struct parse_opt_s *opt, int argc, const char *argv[])
opt->step = 0.0;
opt->grow = 1.1;
opt->graph = false;
opt->best = false;
opt->average = false;
opt->repeat = 1;
for(int i = 1; i < argc ; i++)
@@ -87,6 +89,12 @@ parse_config(struct parse_opt_s *opt, int argc, const char *argv[])
opt->repeat = strtol(argv[i], &end, 10);
} else if (strcmp(argv[i], "--graph") == 0) {
opt->graph = true;
} else if (strcmp(argv[i], "--best") == 0) {
opt->best = true;
opt->average = false;
} else if (strcmp(argv[i], "--average") == 0) {
opt->average = true;
opt->best = false;
} else {
fprintf(stderr, "ERROR: Option unkown: %s.\n",
argv[i]);
@@ -147,22 +155,25 @@ test(const char library[], size_t n, const config_func_t functions[], int argc,
// Do the bench
for(double n = from; n <= to ; n = (arg.grow == 0 ? n + arg.step : n * arg.grow))
{
double t = (1.0/0.0);
double avg = 0.0;
double best = (1.0/0.0);
double avg = 0.0;
if (functions[i].init != NULL)
functions[i].init(n);
for(unsigned r = 0; r < arg.repeat; r++) {
double t0 = test_function(arg.graph ? NULL : functions[i].funcname, (size_t) n, functions[i].func);
t = t0 < t ? t0 : t;
double t0 = test_function(arg.graph|arg.best|arg.average ? NULL : functions[i].funcname, (size_t) n, functions[i].func);
best = t0 < best ? t0 : best;
avg += t0;
}
if (functions[i].clear != NULL)
functions[i].clear();
if (arg.graph)
fprintf(graph_file, "%f %f\n", n, t);
else if (arg.repeat > 1) {
printf ("%20.20s time %lu ms for n = %lu *** BEST ***\n", functions[i].funcname, (unsigned long) t, (unsigned long) n);
printf ("%20.20s time %lu ms for n = %lu *** AVERAGE ***\n", functions[i].funcname, (unsigned long) (avg/arg.repeat), (unsigned long) n);
avg /= arg.repeat;
if (arg.graph) {
fprintf(graph_file, "%f %f\n", n, arg.average ? avg : best);
} else if (arg.repeat > 1) {
if (arg.average == false)
printf ("%20.20s time %lu ms for n = %lu *** BEST ***\n", functions[i].funcname, (unsigned long) best, (unsigned long) n);
if (arg.best == false)
printf ("%20.20s time %lu ms for n = %lu *** AVERAGE ***\n", functions[i].funcname, (unsigned long) avg, (unsigned long) n);
}
}
if (arg.graph) {