annotate src/fftw-3.3.8/libbench2/timer.c @ 82:d0c2a83c1364

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