glibc/benchtests/bench-timing.h

76 lines
2.6 KiB
C
Raw Normal View History

/* Define timing macros.
Copyright (C) 2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <hp-timing.h>
#include <stdint.h>
#if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME
# define GL(x) _##x
# define GLRO(x) _##x
hp_timing_t _dl_hp_timing_overhead;
typedef hp_timing_t timing_t;
# define TIMING_INIT(res) \
({ \
HP_TIMING_DIFF_INIT(); \
(res) = 1; \
})
# define TIMING_NOW(var) HP_TIMING_NOW (var)
# define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
# define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
# define TIMING_PRINT_STATS(func, d_total_s, d_iters, d_total_i, max, min) \
printf ("%s: ITERS:%g: TOTAL:%gMcy, MAX:%gcy, MIN:%gcy, %g calls/Mcy\n", \
(func), (d_total_i), (d_total_s) * 1e-6, (max) / (d_iters), \
(min) / (d_iters), 1e6 * (d_total_i) / (d_total_s));
#else
#include <time.h>
typedef uint64_t timing_t;
/* Measure the resolution of the clock so we can scale the number of
benchmark iterations by this value. */
# define TIMING_INIT(res) \
({ \
struct timespec start; \
clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start); \
(res) = start.tv_nsec; \
})
# define TIMING_NOW(var) \
({ \
struct timespec tv; \
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv); \
(var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec); \
})
# define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
# define TIMING_ACCUM(sum, diff) (sum) += (diff)
# define TIMING_PRINT_STATS(func, d_total_s, d_iters, d_total_i, max, min) \
printf ("%s: ITERS:%g: TOTAL:%gs, MAX:%gns, MIN:%gns, %g iter/s\n", \
(func), (d_total_i), (d_total_s) * 1e-9, (max) / (d_iters), \
(min) / (d_iters), 1e9 * (d_total_i) / (d_total_s))
#endif
benchtests: Switch string benchmarks to use bench-timing.h. Switch the string benchmarks to using bench-timing.h instead of hp-timing.h directly. This allows the string benchmarks to be run usefully on architectures such as ARM that do not have support for hp-timing.h. In order to do this the tests have been changed from timing each individual call and picking the lowest execution time recorded to timing a number of calls and taking the mean execution time. ChangeLog: 2013-09-04 Will Newton <will.newton@linaro.org> * benchtests/bench-timing.h (TIMING_PRINT_MEAN): New macro. * benchtests/bench-string.h: Include bench-timing.h instead of including hp-timing.h directly. (INNER_LOOP_ITERS): New define. (HP_TIMING_BEST): Delete macro. (test_init): Remove call to HP_TIMING_DIFF_INIT. * benchtests/bench-memccpy.c: Use bench-timing.h macros instead of hp-timing.h macros. * benchtests/bench-memchr.c: Likewise. * benchtests/bench-memcmp.c: Likewise. * benchtests/bench-memcpy.c: Likewise. * benchtests/bench-memmem.c: Likewise. * benchtests/bench-memmove.c: Likewise. * benchtests/bench-memset.c: Likewise. * benchtests/bench-rawmemchr.c: Likewise. * benchtests/bench-strcasecmp.c: Likewise. * benchtests/bench-strcasestr.c: Likewise. * benchtests/bench-strcat.c: Likewise. * benchtests/bench-strchr.c: Likewise. * benchtests/bench-strcmp.c: Likewise. * benchtests/bench-strcpy.c: Likewise. * benchtests/bench-strcpy_chk.c: Likewise. * benchtests/bench-strlen.c: Likewise. * benchtests/bench-strncasecmp.c: Likewise. * benchtests/bench-strncat.c: Likewise. * benchtests/bench-strncmp.c: Likewise. * benchtests/bench-strncpy.c: Likewise. * benchtests/bench-strnlen.c: Likewise. * benchtests/bench-strpbrk.c: Likewise. * benchtests/bench-strrchr.c: Likewise. * benchtests/bench-strspn.c: Likewise. * benchtests/bench-strstr.c: Likewise.
2013-09-02 15:13:50 +02:00
#define TIMING_PRINT_MEAN(d_total_s, d_iters) \
printf ("\t%g", (d_total_s) / (d_iters))