Blame benchtests/bench-timing.h

Packit 6c4009
/* Define timing macros.
Packit 6c4009
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#undef attribute_hidden
Packit 6c4009
#define attribute_hidden
Packit 6c4009
#include <hp-timing.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
Packit Service 3cb138
#if HP_TIMING_INLINE && !defined USE_CLOCK_GETTIME
Packit 6c4009
# define GL(x) _##x
Packit 6c4009
# define GLRO(x) _##x
Packit 6c4009
typedef hp_timing_t timing_t;
Packit 6c4009
Packit 6c4009
# define TIMING_TYPE "hp_timing"
Packit 6c4009
Packit 6c4009
# define TIMING_INIT(res) ({ (res) = 1; })
Packit 6c4009
Packit 6c4009
# define TIMING_NOW(var) HP_TIMING_NOW (var)
Packit 6c4009
# define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end))
Packit 6c4009
# define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff))
Packit 6c4009
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
#include <time.h>
Packit 6c4009
typedef uint64_t timing_t;
Packit 6c4009
Packit 6c4009
# define TIMING_TYPE "clock_gettime"
Packit 6c4009
Packit 6c4009
/* Measure the resolution of the clock so we can scale the number of
Packit 6c4009
   benchmark iterations by this value.  */
Packit 6c4009
# define TIMING_INIT(res) \
Packit 6c4009
({									      \
Packit 6c4009
  struct timespec start;						      \
Packit 6c4009
  clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start;;			      \
Packit 6c4009
  (res) = start.tv_nsec;					      \
Packit 6c4009
})
Packit 6c4009
Packit 6c4009
# define TIMING_NOW(var) \
Packit 6c4009
({									      \
Packit 6c4009
  struct timespec tv;							      \
Packit 6c4009
  clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv;;			      \
Packit 6c4009
  (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec);	      \
Packit 6c4009
})
Packit 6c4009
Packit 6c4009
# define TIMING_DIFF(diff, start, end) (diff) = (end) - (start)
Packit 6c4009
# define TIMING_ACCUM(sum, diff) (sum) += (diff)
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#define TIMING_PRINT_MEAN(d_total_s, d_iters) \
Packit 6c4009
  printf ("\t%g", (d_total_s) / (d_iters))