Remove THREAD_STATS.
[glibc.git] / benchtests / bench-timing.h
blob13fc9467a04098aab3d838a39153fdd273bba566
1 /* Define timing macros.
2 Copyright (C) 2013-2014 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 <hp-timing.h>
20 #include <stdint.h>
22 #if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME
23 # define GL(x) _##x
24 # define GLRO(x) _##x
25 hp_timing_t _dl_hp_timing_overhead;
26 typedef hp_timing_t timing_t;
28 # define TIMING_INIT(res) \
29 ({ \
30 HP_TIMING_DIFF_INIT(); \
31 (res) = 1; \
34 # define TIMING_NOW(var) HP_TIMING_NOW (var)
35 # define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
36 # define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
38 # define TIMING_PRINT_STATS(func, d_total_s, d_iters, d_total_i, max, min) \
39 printf ("%s: ITERS:%g: TOTAL:%gMcy, MAX:%gcy, MIN:%gcy, %g calls/Mcy\n", \
40 (func), (d_total_i), (d_total_s) * 1e-6, (max) / (d_iters), \
41 (min) / (d_iters), 1e6 * (d_total_i) / (d_total_s));
43 #else
45 #include <time.h>
46 typedef uint64_t timing_t;
48 /* Measure the resolution of the clock so we can scale the number of
49 benchmark iterations by this value. */
50 # define TIMING_INIT(res) \
51 ({ \
52 struct timespec start; \
53 clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start); \
54 (res) = start.tv_nsec; \
57 # define TIMING_NOW(var) \
58 ({ \
59 struct timespec tv; \
60 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv); \
61 (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec); \
64 # define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
65 # define TIMING_ACCUM(sum, diff) (sum) += (diff)
67 # define TIMING_PRINT_STATS(func, d_total_s, d_iters, d_total_i, max, min) \
68 printf ("%s: ITERS:%g: TOTAL:%gs, MAX:%gns, MIN:%gns, %g iter/s\n", \
69 (func), (d_total_i), (d_total_s) * 1e-9, (max) / (d_iters), \
70 (min) / (d_iters), 1e9 * (d_total_i) / (d_total_s))
72 #endif
74 #define TIMING_PRINT_MEAN(d_total_s, d_iters) \
75 printf ("\t%g", (d_total_s) / (d_iters))