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