This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] randomize benchtests
- From: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 22 Apr 2013 17:44:14 +0530
- Subject: Re: [PATCH] randomize benchtests
- References: <20130422120018 dot GA30323 at domone dot kolej dot mff dot cuni dot cz>
On 22 April 2013 17:30, OndÅej BÃlka <neleai@seznam.cz> wrote:
> uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
> struct timespec start, end;
> -
> + int seed = 42;
You get the same sequence all the time. Use getpid() as seed or even time().
> + 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);
This is wrong. The interval also has the time taken to call rand_r.
> - 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);
If you have total iterations and iters/sec, you can compute average
directly. You've gotten rid of two pieces of core information to add
one piece of derived information. I am not very picky about what the
output looks like though.
Also, if you wait for the HP_TIMING patch to be reviewed and checked
in, you'll get cycles as a unit instead of nanoseconds.
Siddhesh
--
http://siddhesh.in