dl_open_worker: Memset all of seen array.
[glibc.git] / benchtests / bench-skeleton.c
blob13f986d81727c437e4d707d5691b05d4b4069f6b
1 /* Skeleton for benchmark programs.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <string.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <time.h>
23 #include <inttypes.h>
25 int
26 main (int argc, char **argv)
28 unsigned long i, j, k;
29 uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
30 struct timespec start, end;
32 memset (&start, 0, sizeof (start));
33 memset (&end, 0, sizeof (end));
35 clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start);
37 /* Measure 1000 times the resolution of the clock. So for a 1ns resolution
38 clock, we measure 1000 iterations of the function call at a time.
39 Measurements close to the minimum clock resolution won't make much sense,
40 but it's better than having nothing at all. */
41 unsigned long iters = 1000 * start.tv_nsec;
42 unsigned long total_iters = ITER / iters;
44 for (i = 0; i < NUM_SAMPLES; i++)
46 for (j = 0; j < total_iters; j ++)
48 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start);
49 for (k = 0; k < iters; k++)
50 BENCH_FUNC(i);
51 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end);
53 uint64_t cur = (end.tv_nsec - start.tv_nsec
54 + ((end.tv_sec - start.tv_sec)
55 * (uint64_t) 1000000000));
57 if (cur > max)
58 max = cur;
60 if (cur < min)
61 min = cur;
63 total += cur;
67 double d_total_s = total * 1e-9;
68 double d_iters = iters;
69 double d_total_i = (double)ITER * NUM_SAMPLES;
70 printf (FUNCNAME ": ITERS:%g: TOTAL:%gs, MAX:%gns, MIN:%gns, %g iter/s\n",
71 d_total_i, d_total_s, max / d_iters, min / d_iters,
72 d_total_i / d_total_s);
74 return 0;