Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | |
2 | /* |
||
3 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology |
||
4 | * |
||
5 | * This program is free software; you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation; either version 2 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * |
||
10 | * This program is distributed in the hope that it will be useful, |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | * GNU General Public License for more details. |
||
14 | * |
||
15 | * You should have received a copy of the GNU General Public License |
||
16 | * along with this program; if not, write to the Free Software |
||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | * |
||
19 | */ |
||
20 | |||
21 | /* |
||
22 | * timer.c -- this file measures the execution time of |
||
23 | * ffts. This information is used by the planner. |
||
24 | */ |
||
25 | |||
26 | /* $Id: timer.c,v 1.1.1.1 2002-03-29 14:12:57 pj Exp $ */ |
||
27 | |||
28 | #include <ports/time.h> |
||
29 | #include <ports/fftw-int.h> |
||
30 | #include <ports/math.h> |
||
31 | #include <ports/stdlib.h> |
||
32 | |||
33 | /********************* System-specific Timing Support *********************/ |
||
34 | |||
35 | #if defined(HAVE_MAC_TIMER) && !defined(HAVE_MAC_PCI_TIMER) |
||
36 | |||
37 | /* Use Macintosh Time Manager to get the time: */ |
||
38 | |||
39 | /* |
||
40 | * make sure compiler (CW) recognizes the pascal keywords that are in |
||
41 | * Timer.h |
||
42 | */ |
||
43 | #pragma only_std_keywords off |
||
44 | |||
45 | #include <ports/Timer.h> |
||
46 | |||
47 | #pragma only_std_keywords reset |
||
48 | |||
49 | fftw_time get_Mac_microseconds(void) |
||
50 | { |
||
51 | fftw_time t; |
||
52 | UnsignedWide microsec; /* |
||
53 | * microsec.lo and microsec.hi are |
||
54 | * unsigned long's, and are the two parts |
||
55 | * of a 64 bit unsigned integer |
||
56 | */ |
||
57 | |||
58 | Microseconds(µsec); /* get time in microseconds */ |
||
59 | |||
60 | /* store lo and hi words into our structure: */ |
||
61 | t.lo = microsec.lo; |
||
62 | t.hi = microsec.hi; |
||
63 | |||
64 | return t; |
||
65 | } |
||
66 | |||
67 | fftw_time fftw_time_diff(fftw_time t1, fftw_time t2) |
||
68 | /* |
||
69 | * This function takes the difference t1 - t2 of two 64 bit |
||
70 | * integers, represented by the 32 bit lo and hi words. |
||
71 | * if t1 < t2, returns 0. |
||
72 | */ |
||
73 | { |
||
74 | fftw_time diff; |
||
75 | |||
76 | if (t1.hi < t2.hi) { /* something is wrong...t1 < t2! */ |
||
77 | diff.hi = diff.lo = 0; |
||
78 | return diff; |
||
79 | } else |
||
80 | diff.hi = t1.hi - t2.hi; |
||
81 | |||
82 | if (t1.lo < t2.lo) { |
||
83 | if (diff.hi > 0) |
||
84 | diff.hi -= 1; /* carry */ |
||
85 | else { /* something is wrong...t1 < t2! */ |
||
86 | diff.hi = diff.lo = 0; |
||
87 | return diff; |
||
88 | } |
||
89 | } |
||
90 | diff.lo = t1.lo - t2.lo; |
||
91 | |||
92 | return diff; |
||
93 | } |
||
94 | |||
95 | #endif |
||
96 | |||
97 | #ifdef HAVE_WIN32_TIMER |
||
98 | #include <ports/windows.h> |
||
99 | |||
100 | static LARGE_INTEGER gFreq; |
||
101 | static int gHaveHiResTimer = 0; |
||
102 | static int gFirstTime = 1; |
||
103 | |||
104 | unsigned long GetPerfTime(void) |
||
105 | { |
||
106 | LARGE_INTEGER lCounter; |
||
107 | |||
108 | if (gFirstTime) { |
||
109 | gFirstTime = 0; |
||
110 | |||
111 | if (QueryPerformanceFrequency(&gFreq)) { |
||
112 | gHaveHiResTimer = 1; |
||
113 | } |
||
114 | } |
||
115 | if (gHaveHiResTimer) { |
||
116 | QueryPerformanceCounter(&lCounter); |
||
117 | return lCounter.u.LowPart; |
||
118 | } else { |
||
119 | return (unsigned long) clock(); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | double GetPerfSec(double pTime) |
||
124 | { |
||
125 | if (gHaveHiResTimer) { |
||
126 | return pTime / gFreq.u.LowPart; // assumes HighPart==0 |
||
127 | |||
128 | } else { |
||
129 | return pTime / CLOCKS_PER_SEC; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | #endif /* HAVE_WIN32_TIMER */ |
||
134 | |||
135 | #if defined(FFTW_USE_GETTIMEOFDAY) |
||
136 | |||
137 | /* timer support routines for systems having gettimeofday */ |
||
138 | |||
139 | #ifdef HAVE_BSDGETTIMEOFDAY |
||
140 | #define gettimeofday BSDgettimeofday |
||
141 | #endif |
||
142 | |||
143 | fftw_time fftw_gettimeofday_get_time(void) |
||
144 | { |
||
145 | struct timeval tv; |
||
146 | gettimeofday(&tv, 0); |
||
147 | return tv; |
||
148 | } |
||
149 | |||
150 | fftw_time fftw_gettimeofday_time_diff(fftw_time t1, fftw_time t2) |
||
151 | { |
||
152 | fftw_time diff; |
||
153 | |||
154 | diff.tv_sec = t1.tv_sec - t2.tv_sec; |
||
155 | diff.tv_usec = t1.tv_usec - t2.tv_usec; |
||
156 | /* normalize */ |
||
157 | while (diff.tv_usec < 0) { |
||
158 | diff.tv_usec += 1000000L; |
||
159 | diff.tv_sec -= 1; |
||
160 | } |
||
161 | |||
162 | return diff; |
||
163 | } |
||
164 | #endif |