Mercurial > mplayer.hg
annotate osdep/timer-darwin.c @ 12385:b5c106b694e4
this isn't actually stupid, but it's not valid C and gcc 3.5 rejects it as such
author | rfelker |
---|---|
date | Sat, 01 May 2004 20:15:21 +0000 |
parents | d12758db79aa |
children | f9755d9c479a |
rev | line source |
---|---|
10148
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
1 /* |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
2 * Precise timer routines using Mach kernel-space timing. |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
3 * |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
4 * It reports to be accurate by ~20us, unless the task is preempted. |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
5 * |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
6 * (C) 2003 Dan Christiansen |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
7 * |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
8 * Released into the public domain. |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
9 */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
10 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
11 #include <unistd.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
12 #include <stdlib.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
13 #include <stdio.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
14 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
15 #include <mach/mach_time.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
16 #include <mach/mach.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
17 #include <mach/clock.h> |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
18 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
19 #include "../config.h" |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
20 #include "../mp_msg.h" |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
21 #include "timer.h" |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
22 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
23 /* Utility macros for mach_timespec_t - it uses nsec rather than usec */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
24 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
25 /* returns time from t1 to t2, in seconds (as float) */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
26 #define diff_time(t1, t2) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
27 (((t2).tv_sec - (t1).tv_sec) + \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
28 ((t2).tv_nsec - (t1).tv_nsec) / 1e9) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
29 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
30 /* returns time from t1 to t2, in microseconds (as integer) */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
31 #define udiff_time(t1, t2) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
32 (((t2).tv_sec - (t1).tv_sec) * 1000000 + \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
33 ((t2).tv_nsec - (t1).tv_nsec) / 1000) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
34 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
35 /* returns float value of t, in seconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
36 #define time_to_float(t) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
37 ((t).tv_sec + (t).tv_nsec / 1e9) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
38 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
39 /* returns integer value of t, in microseconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
40 #define time_to_usec(t) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
41 ((t).tv_sec * 1000000 + (t).tv_nsec / 1000) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
42 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
43 /* sets ts to the value of f, in seconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
44 #define float_to_time(f, ts) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
45 do { \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
46 (ts).tv_sec = (unsigned int)(f); \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
47 (ts).tv_nsec = (int)(((f) - (ts).sec) / 1000000000.0); \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
48 } while (0) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
49 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
50 /* sets ts to the value of i, in microseconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
51 #define usec_to_time(i, ts) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
52 do { \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
53 (ts).tv_sec = (i) / 1000000; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
54 (ts).tv_nsec = (i) % 1000000 * 1000; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
55 } while (0) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
56 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
57 #define time_uadd(i, ts) \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
58 do { \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
59 (ts).tv_sec += (i) / 1000000; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
60 (ts).tv_nsec += (i) % 1000000 * 1000; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
61 while ((ts).tv_nsec > 1000000000) { \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
62 (ts).tv_sec++; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
63 (ts).tv_nsec -= 1000000000; \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
64 } \ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
65 } while (0) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
66 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
67 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
68 /* global variables */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
69 static double relative_time, startup_time; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
70 static double timebase_ratio; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
71 static mach_port_t clock_port; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
72 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
73 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
74 /* sleep usec_delay microseconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
75 int usec_sleep(int usec_delay) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
76 { |
11867 | 77 #if 0 |
10148
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
78 mach_timespec_t start_time, end_time; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
79 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
80 clock_get_time(clock_port, &start_time); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
81 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
82 end_time = start_time; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
83 time_uadd(usec_delay, end_time); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
84 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
85 clock_sleep(clock_port, TIME_ABSOLUTE, end_time, NULL); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
86 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
87 clock_get_time(clock_port, &end_time); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
88 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
89 return usec_delay - udiff_time(start_time, end_time); |
11867 | 90 #else |
91 usleep(usec_delay); | |
92 #endif | |
10148
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
93 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
94 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
95 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
96 /* Returns current time in microseconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
97 unsigned int GetTimer() |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
98 { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
99 return (unsigned int)((mach_absolute_time() * timebase_ratio - startup_time) |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
100 * 1e6); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
101 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
102 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
103 /* Returns current time in milliseconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
104 unsigned int GetTimerMS() |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
105 { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
106 return (unsigned int)(GetTimer() / 1000); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
107 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
108 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
109 /* Returns time spent between now and last call in seconds */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
110 float GetRelativeTime() |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
111 { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
112 double last_time; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
113 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
114 last_time = relative_time; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
115 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
116 relative_time = mach_absolute_time() * timebase_ratio; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
117 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
118 return (float)(relative_time-last_time); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
119 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
120 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
121 /* Initialize timer, must be called at least once at start */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
122 void InitTimer() |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
123 { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
124 struct mach_timebase_info timebase; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
125 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
126 /* get base for mach_absolute_time() */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
127 mach_timebase_info(&timebase); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
128 timebase_ratio = (double)timebase.numer / (double)timebase.denom |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
129 * (double)1e-9; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
130 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
131 /* get mach port for the clock */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
132 host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &clock_port); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
133 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
134 /* prepare for GetRelativeTime() */ |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
135 relative_time = startup_time = |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
136 (double)(mach_absolute_time() * timebase_ratio); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
137 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
138 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
139 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
140 #if 0 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
141 int main() |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
142 { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
143 const long delay = 0.001*1e6; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
144 const unsigned short attempts = 100; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
145 int i,j[attempts],t[attempts],r[attempts]; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
146 double sqtotal; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
147 double total; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
148 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
149 InitTimer(); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
150 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
151 for (i = 0; i < attempts; i++) { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
152 t[i] = j[i] = GetTimer(); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
153 r[i] = usec_sleep(delay); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
154 j[i] = delay-(GetTimer() - j[i]); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
155 fflush(stdout); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
156 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
157 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
158 for (i = 0; i < attempts; i++) { |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
159 sqtotal += j[i]*j[i]; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
160 total += j[i]; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
161 printf("%2i=%0.06g \tr: %9i\tj: %9i\tr - j:%9i\n", |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
162 i, t[i] / 1e6, r[i], j[i], r[i] - j[i]); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
163 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
164 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
165 printf("attempts: %i\ttotal=%g\trms=%g\tavg=%g\n", attempts, total, |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
166 sqrt(sqtotal/attempts),total/attempts); |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
167 |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
168 return 0; |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
169 } |
139b44930abc
Precise timer for Darwin (it's more accurate than timer-macosx.c)
alex
parents:
diff
changeset
|
170 #endif |