1 /* Actual benchmark kernels used by bench-hash-funcs.h
2 Copyright (C) 2022-2024 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 <https://www.gnu.org/licenses/>. */
20 #include "bench-util.h"
22 /* We go through the trouble of using macros here because many of the
23 hash functions are meant to be inlined so its not fair to benchmark
24 them with a function pointer where they won't be inlinable. */
28 # define RUN_FUNC SIMPLE_TEST_FUNC
29 # define POSTFIX _simple
31 # define RUN_FUNC TEST_FUNC
32 # define POSTFIX _optimized
35 #define PRIMITIVE_CAT(x, y) x ## y
36 #define CAT(x, y) PRIMITIVE_CAT (x, y)
38 static double __attribute__ ((noinline, noclone))
39 CAT (do_one_test_kernel, POSTFIX) (const char *s, size_t len)
43 timing_t start, stop, cur;
46 for (iters = NFIXED_ITERS / 32; iters; --iters)
47 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (s, len));
50 for (iters = NFIXED_ITERS; iters; --iters)
51 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (s, len));
55 TIMING_DIFF (cur, start, stop);
58 return (double) cur / (double) NFIXED_ITERS;
61 static double __attribute__ ((noinline, noclone))
62 CAT (do_rand_test_kernel, POSTFIX) (char const *bufs,
63 unsigned int const *sizes)
65 unsigned int i, iters;
67 timing_t start, stop, cur;
70 for (i = 0, offset = 0; i < NRAND_BUFS; ++i, offset += RAND_BENCH_MAX_LEN)
71 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (bufs + offset, sizes[i]));
74 for (iters = NRAND_ITERS; iters; --iters)
76 for (i = 0, offset = 0; i < NRAND_BUFS;
77 ++i, offset += RAND_BENCH_MAX_LEN)
78 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (bufs + offset, sizes[i]));
83 TIMING_DIFF (cur, start, stop);
86 return (double) cur / (double) (NRAND_ITERS * NRAND_BUFS);