annotate fft/fftw/fftw-3.3.4/libbench2/timer.c @ 40:223f770b5341 kissfft-double tip

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