annotate src/fftw-3.3.8/libbench2/timer.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2001 Matteo Frigo
cannam@167 3 * Copyright (c) 2001 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21
cannam@167 22 #include "libbench2/bench.h"
cannam@167 23 #include <stdio.h>
cannam@167 24
cannam@167 25 /*
cannam@167 26 * System-dependent timing functions:
cannam@167 27 */
cannam@167 28 #ifdef HAVE_SYS_TIME_H
cannam@167 29 #include <sys/time.h>
cannam@167 30 #endif
cannam@167 31
cannam@167 32 #ifdef HAVE_UNISTD_H
cannam@167 33 #include <unistd.h>
cannam@167 34 #endif
cannam@167 35
cannam@167 36 #ifdef HAVE_BSDGETTIMEOFDAY
cannam@167 37 #ifndef HAVE_GETTIMEOFDAY
cannam@167 38 #define gettimeofday BSDgettimeofday
cannam@167 39 #define HAVE_GETTIMEOFDAY 1
cannam@167 40 #endif
cannam@167 41 #endif
cannam@167 42
cannam@167 43 double time_min;
cannam@167 44 int time_repeat;
cannam@167 45
cannam@167 46 #if !defined(HAVE_TIMER) && (defined(__WIN32__) || defined(_WIN32) || defined(_WINDOWS) || defined(__CYGWIN__))
cannam@167 47 #include <windows.h>
cannam@167 48 typedef LARGE_INTEGER mytime;
cannam@167 49
cannam@167 50 static mytime get_time(void)
cannam@167 51 {
cannam@167 52 mytime tv;
cannam@167 53 QueryPerformanceCounter(&tv);
cannam@167 54 return tv;
cannam@167 55 }
cannam@167 56
cannam@167 57 static double elapsed(mytime t1, mytime t0)
cannam@167 58 {
cannam@167 59 LARGE_INTEGER freq;
cannam@167 60 QueryPerformanceFrequency(&freq);
cannam@167 61 return (((double) t1.QuadPart - (double) t0.QuadPart)) /
cannam@167 62 ((double) freq.QuadPart);
cannam@167 63 }
cannam@167 64
cannam@167 65 #define HAVE_TIMER
cannam@167 66 #endif
cannam@167 67
cannam@167 68
cannam@167 69 #if defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_TIMER)
cannam@167 70 typedef struct timeval mytime;
cannam@167 71
cannam@167 72 static mytime get_time(void)
cannam@167 73 {
cannam@167 74 struct timeval tv;
cannam@167 75 gettimeofday(&tv, 0);
cannam@167 76 return tv;
cannam@167 77 }
cannam@167 78
cannam@167 79 static double elapsed(mytime t1, mytime t0)
cannam@167 80 {
cannam@167 81 return ((double) t1.tv_sec - (double) t0.tv_sec) +
cannam@167 82 ((double) t1.tv_usec - (double) t0.tv_usec) * 1.0E-6;
cannam@167 83 }
cannam@167 84
cannam@167 85 #define HAVE_TIMER
cannam@167 86 #endif
cannam@167 87
cannam@167 88 #ifndef HAVE_TIMER
cannam@167 89 #error "timer not defined"
cannam@167 90 #endif
cannam@167 91
cannam@167 92 static double calibrate(void)
cannam@167 93 {
cannam@167 94 /* there seems to be no reasonable way to calibrate the
cannam@167 95 clock automatically any longer. Grrr... */
cannam@167 96
cannam@167 97 return 0.01;
cannam@167 98 }
cannam@167 99
cannam@167 100
cannam@167 101 void timer_init(double tmin, int repeat)
cannam@167 102 {
cannam@167 103 static int inited = 0;
cannam@167 104
cannam@167 105 if (inited)
cannam@167 106 return;
cannam@167 107 inited = 1;
cannam@167 108
cannam@167 109 if (!repeat)
cannam@167 110 repeat = 8;
cannam@167 111 time_repeat = repeat;
cannam@167 112
cannam@167 113 if (tmin > 0)
cannam@167 114 time_min = tmin;
cannam@167 115 else
cannam@167 116 time_min = calibrate();
cannam@167 117 }
cannam@167 118
cannam@167 119 static mytime t0[BENCH_NTIMERS];
cannam@167 120
cannam@167 121 void timer_start(int n)
cannam@167 122 {
cannam@167 123 BENCH_ASSERT(n >= 0 && n < BENCH_NTIMERS);
cannam@167 124 t0[n] = get_time();
cannam@167 125 }
cannam@167 126
cannam@167 127 double timer_stop(int n)
cannam@167 128 {
cannam@167 129 mytime t1;
cannam@167 130 BENCH_ASSERT(n >= 0 && n < BENCH_NTIMERS);
cannam@167 131 t1 = get_time();
cannam@167 132 return elapsed(t1, t0[n]);
cannam@167 133 }
cannam@167 134