This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] randomize benchtests
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Mon, 22 Apr 2013 14:00:18 +0200
- Subject: [PATCH] randomize benchtests
Hi,
I added ordering randomization in benchtest to capture more realistic
data. This takes into account branch misprediction which easily is 20%
of running time.
Indepentently I print results in saner metrics namely average,
minimum and maximum time.
Do you know more portable way to get CPU frequency than reading /dev/cpuinfo?
I need that to display data at cycles which are more natural unit than
nanoseconds.
* benchtests/bench-skeleton.c (main): Randomize ordering.
---
benchtests/bench-skeleton.c | 44 +++++++++++++++++++-----------------------
1 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c
index 13f986d..3061633 100644
--- a/benchtests/bench-skeleton.c
+++ b/benchtests/bench-skeleton.c
@@ -18,6 +18,7 @@
#include <string.h>
#include <stdint.h>
+#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <inttypes.h>
@@ -28,7 +29,7 @@ main (int argc, char **argv)
unsigned long i, j, k;
uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
struct timespec start, end;
-
+ int seed = 42;
memset (&start, 0, sizeof (start));
memset (&end, 0, sizeof (end));
@@ -41,35 +42,30 @@ main (int argc, char **argv)
unsigned long iters = 1000 * start.tv_nsec;
unsigned long total_iters = ITER / iters;
- for (i = 0; i < NUM_SAMPLES; i++)
+ for (j = 0; j < NUM_SAMPLES * total_iters; j ++)
{
- for (j = 0; j < total_iters; j ++)
- {
- clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start);
- for (k = 0; k < iters; k++)
- BENCH_FUNC(i);
- clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end);
-
- uint64_t cur = (end.tv_nsec - start.tv_nsec
- + ((end.tv_sec - start.tv_sec)
- * (uint64_t) 1000000000));
-
- if (cur > max)
- max = cur;
+ clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start);
+ for (k = 0; k < iters; k++)
+ {
+ i = rand_r (&seed)%NUM_SAMPLES;
+ BENCH_FUNC(i);
+ }
+ clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end);
- if (cur < min)
- min = cur;
+ uint64_t cur = (end.tv_nsec - start.tv_nsec
+ + ((end.tv_sec - start.tv_sec)
+ * (uint64_t) 1000000000));
- total += cur;
- }
+ if (cur > max)
+ max = cur;
+ if (cur < min)
+ min = cur;
+ total += cur;
}
- double d_total_s = total * 1e-9;
- double d_iters = iters;
double d_total_i = (double)ITER * NUM_SAMPLES;
- printf (FUNCNAME ": ITERS:%g: TOTAL:%gs, MAX:%gns, MIN:%gns, %g iter/s\n",
- d_total_i, d_total_s, max / d_iters, min / d_iters,
- d_total_i / d_total_s);
+ printf (FUNCNAME ": AVERAGE:%gns\tMIN:%gns,\tMAX:%gns\n",
+ d_total / d_total_i, min / iters, max / iters);
return 0;
}
--
1.7.4.4