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