Update IA64 libm-test-ulps
[glibc.git] / benchtests / bench-timing.h
blobe6778d28c65307ab4746a0a5e58c9d41ce0f742a
1 /* Define timing macros.
2 Copyright (C) 2013-2017 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 typedef hp_timing_t timing_t;
27 # define TIMING_TYPE "hp_timing"
29 # define TIMING_INIT(res) ({ (res) = 1; })
31 # define TIMING_NOW(var) HP_TIMING_NOW (var)
32 # define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
33 # define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
35 #else
37 #include <time.h>
38 typedef uint64_t timing_t;
40 # define TIMING_TYPE "clock_gettime"
42 /* Measure the resolution of the clock so we can scale the number of
43 benchmark iterations by this value. */
44 # define TIMING_INIT(res) \
45 ({ \
46 struct timespec start; \
47 clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start); \
48 (res) = start.tv_nsec; \
51 # define TIMING_NOW(var) \
52 ({ \
53 struct timespec tv; \
54 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv); \
55 (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec); \
58 # define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
59 # define TIMING_ACCUM(sum, diff) (sum) += (diff)
61 #endif
63 #define TIMING_PRINT_MEAN(d_total_s, d_iters) \
64 printf ("\t%g", (d_total_s) / (d_iters))