annotate src/fftw-3.3.5/libbench2/timer.c @ 84:08ae793730bd

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