]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-timing.h
misc/test-errno-linux: Handle EINVAL from quotactl
[thirdparty/glibc.git] / benchtests / bench-timing.h
CommitLineData
43fe811b 1/* Define timing macros.
688903eb 2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
43fe811b
SP
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
fbce6f72 19#undef attribute_hidden
f1c8185d 20#define attribute_hidden
43fe811b
SP
21#include <hp-timing.h>
22#include <stdint.h>
23
24#if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME
25# define GL(x) _##x
26# define GLRO(x) _##x
43fe811b
SP
27typedef hp_timing_t timing_t;
28
cb5e4aad
SP
29# define TIMING_TYPE "hp_timing"
30
428dd03f 31# define TIMING_INIT(res) ({ (res) = 1; })
43fe811b
SP
32
33# define TIMING_NOW(var) HP_TIMING_NOW (var)
34# define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
35# define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
36
43fe811b 37#else
e8470ea2
SE
38
39#include <time.h>
43fe811b
SP
40typedef uint64_t timing_t;
41
cb5e4aad
SP
42# define TIMING_TYPE "clock_gettime"
43
b987c776
WN
44/* Measure the resolution of the clock so we can scale the number of
45 benchmark iterations by this value. */
46# define TIMING_INIT(res) \
43fe811b
SP
47({ \
48 struct timespec start; \
49 clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start); \
b987c776 50 (res) = start.tv_nsec; \
43fe811b
SP
51})
52
53# define TIMING_NOW(var) \
54({ \
55 struct timespec tv; \
56 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv); \
57 (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec); \
58})
59
60# define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
61# define TIMING_ACCUM(sum, diff) (sum) += (diff)
62
43fe811b 63#endif
44558701
WN
64
65#define TIMING_PRINT_MEAN(d_total_s, d_iters) \
66 printf ("\t%g", (d_total_s) / (d_iters))