Add repeat option for bench
This commit is contained in:
1 parent
7263629c55
commit
e99735d2b6
2 files changed
+27
-5
No files matched your search
+25
-3
@@ -26,8 +26,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// The global result
|
||||||
unsigned long g_result;
|
unsigned long g_result;
|
||||||
|
|
||||||
|
// The rand value
|
||||||
|
#if defined(MULTI_THREAD_MEASURE)
|
||||||
|
M_THREAD_ATTR
|
||||||
|
#endif
|
||||||
|
unsigned int randValue = 0;
|
||||||
|
|
||||||
void compiler_barrier(void *p)
|
void compiler_barrier(void *p)
|
||||||
{
|
{
|
||||||
// Do nothing, but let the compiler thinks that we did.
|
// Do nothing, but let the compiler thinks that we did.
|
||||||
@@ -39,6 +46,7 @@ void compiler_barrier(void *p)
|
|||||||
struct parse_opt_s {
|
struct parse_opt_s {
|
||||||
int test_function;
|
int test_function;
|
||||||
double from, to, step, grow;
|
double from, to, step, grow;
|
||||||
|
unsigned repeat;
|
||||||
bool graph;
|
bool graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,6 +61,7 @@ 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->repeat = 1;
|
||||||
|
|
||||||
for(int i = 1; i < argc ; i++)
|
for(int i = 1; i < argc ; i++)
|
||||||
{
|
{
|
||||||
@@ -73,6 +82,9 @@ parse_config(struct parse_opt_s *opt, int argc, const char *argv[])
|
|||||||
i++;
|
i++;
|
||||||
opt->grow = strtod(argv[i], &end);
|
opt->grow = strtod(argv[i], &end);
|
||||||
opt->step = 0;
|
opt->step = 0;
|
||||||
|
} else if (strcmp(argv[i], "--repeat") == 0) {
|
||||||
|
i++;
|
||||||
|
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 {
|
} else {
|
||||||
@@ -89,7 +101,7 @@ parse_config(struct parse_opt_s *opt, int argc, const char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
opt->test_function = strtol (argv[i], &end, 10);
|
opt->test_function = strtol (argv[i], &end, 10);
|
||||||
if (*end != 0) {
|
if (*end != 0) {
|
||||||
fprintf(stderr, "ERROR: Cannot parse %s. Expected integer\n",
|
fprintf(stderr, "ERROR: Cannot parse %s. Expected function number\n",
|
||||||
argv[i]);
|
argv[i]);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
@@ -115,6 +127,7 @@ test(const char library[], size_t n, const config_func_t functions[], int argc,
|
|||||||
// NUMBER
|
// NUMBER
|
||||||
// --from NUMBER --to NUMBER --step NUMBER --grow NUMBER
|
// --from NUMBER --to NUMBER --step NUMBER --grow NUMBER
|
||||||
// --graph
|
// --graph
|
||||||
|
// --repeat N
|
||||||
struct parse_opt_s arg;
|
struct parse_opt_s arg;
|
||||||
parse_config(&arg, argc, argv);
|
parse_config(&arg, argc, argv);
|
||||||
int i = select_config(arg.test_function, n, functions);
|
int i = select_config(arg.test_function, n, functions);
|
||||||
@@ -134,14 +147,23 @@ 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;
|
double t = (1.0/0.0);
|
||||||
|
double avg = 0.0;
|
||||||
if (functions[i].init != NULL)
|
if (functions[i].init != NULL)
|
||||||
functions[i].init(n);
|
functions[i].init(n);
|
||||||
t = test_function(arg.graph ? NULL : functions[i].funcname, (size_t) n, functions[i].func);
|
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;
|
||||||
|
avg += t0;
|
||||||
|
}
|
||||||
if (functions[i].clear != NULL)
|
if (functions[i].clear != NULL)
|
||||||
functions[i].clear();
|
functions[i].clear();
|
||||||
if (arg.graph)
|
if (arg.graph)
|
||||||
fprintf(graph_file, "%f %f\n", n, t);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (arg.graph) {
|
if (arg.graph) {
|
||||||
fclose(graph_file);
|
fclose(graph_file);
|
||||||
|
|||||||
+2
-2
@@ -90,11 +90,11 @@ cputime (void)
|
|||||||
extern unsigned long g_result;
|
extern unsigned long g_result;
|
||||||
|
|
||||||
// The rand value
|
// The rand value
|
||||||
static
|
extern
|
||||||
#if defined(MULTI_THREAD_MEASURE)
|
#if defined(MULTI_THREAD_MEASURE)
|
||||||
M_THREAD_ATTR
|
M_THREAD_ATTR
|
||||||
#endif
|
#endif
|
||||||
unsigned int randValue = 0;
|
unsigned int randValue;
|
||||||
|
|
||||||
// Pseudo rand value generator.
|
// Pseudo rand value generator.
|
||||||
// Not very random but sufficient and fast enough for the bench
|
// Not very random but sufficient and fast enough for the bench
|
||||||
|
|||||||
Reference in new issue
Block a user