-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathtimer.html
More file actions
277 lines (243 loc) · 7.38 KB
/
timer.html
File metadata and controls
277 lines (243 loc) · 7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<html>
<head>
<title>
TIMER - Compute Elapsed Time
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
TIMER <br> Compute Elapsed Time
</h1>
<hr>
<p>
<b>TIMER</b>
is a directory of MATLAB programs which
compute the elapsed CPU time or wallclock time of a part of a calculation.
</p>
<p>
The idea is that you want to
determine the amount of CPU time taken by a piece of your code, so
you write lines like this:
<pre><tt>
t_start = timer;
...some big calculation...
t_stop = timer;
fprintf ( 1, 'Elapsed CPU time = %f\n', t_stop - t_start );
</pre></tt>
</p>
<p>
MATLAB includes a function <b>CPUTIME</b>, which returns
the CPU time in seconds. This represents the amount of computer time
"used" by your program, and could be somewhat less than the elapsed
wall clock time.
</p>
<p>
MATLAB includes a function <b>CLOCK</b> which returns the YMDHMS
date as a vector of six integers. Two values of <b>CLOCK</b> can be
subtracted, and the difference, or elapsed "wall clock time",
returned in seconds, by the function <b>ETIME</b>.
</p>
<p>
MATLAB includes two functions <b>TIC</b> and <b>TOC</b>. If <b>TIC</b>
is called before something is to be timed, and <b>TOC</b> is called
afterward, then <b>TOC</b> will either print the elapsed wallclock
time if its value is not being copied to a variable, or return the
value of the elapsed wallclock time to a variable.
</p>
<p>
To time an entire program, the simplest method to get the elapsed
wallclock time is to call <b>tic</b> before you run the program
and <b>toc</b> afterwards:
<pre>
tic
my_program
toc
</pre>
If <b>toc</b> is called without an output argument, it prints the elapsed time.
or you can save the output from <b>toc</b> and print it yourself.
<pre>
tic
my_program
wtime = toc
fprintf ( 1, ' MY_PROGRAM took %f seconds to run.\n', wtime );
</pre>
</p>
<p>
For parallel programming, the important thing to measure is the elapsed
wallclock time. This can be found by subtracting an initial reading of
the wallclock time from a final one.
</p>
<p>
The OpenMP system provides a function used as follows:
<pre>
seconds = omp_get_wtime ( )
operations to time;
seconds = omp_get_wtime ( ) - seconds;
</pre>
while the MPI system provides a similar function used as:
<pre>
seconds = MPI_Wtime ( );
operations;
seconds = MPI_Wtime ( ) - seconds;
</pre>
and in MATLAB, wallclock time can be taken with "tic" and "toc":
<pre>
tic;
operation;
seconds = toc;
</pre>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>TIMER</b> is available in
<a href = "../../c_src/timer/timer.html">a C version</a> and
<a href = "../../cpp_src/timer/timer.html">a C++ version</a> and
<a href = "../../f77_src/timer/timer.html">a FORTRAN77 version</a> and
<a href = "../../f_src/timer/timer.html">a FORTRAN90 version</a> and
<a href = "../../m_src/timer/timer.html">a MATLAB version</a> and
<a href = "../../py_src/timer/timer.html">a PYTHON version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/tic_toc/tic_toc.html">
TIC_TOC</a>,
MATLAB programs which
demonstrate some features of MATLAB's tic and toc functions for wallclock timing.
</p>
<p>
<a href = "../../m_src/timestamp/timestamp.html">
TIMESTAMP</a>,
a MATLAB library which
prints out the current YMDHMS date.
</p>
<p>
<a href = "../../m_src/wtime/wtime.html">
WTIME</a>,
a MATLAB library which
returns a reading of the wall clock time in seconds.
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>CPUTIME_TEST</b> uses the CPUTIME routine:
<ul>
<li>
<a href = "timer_cputime_test.m">timer_cputime_test.m</a>,
the main body of the test;
</li>
<li>
<a href = "timer_cputime_test01.m">timer_cputime_test01.m</a>,
test #1;
</li>
<li>
<a href = "timer_cputime_test02.m">timer_cputime_test02.m</a>,
test #2;
</li>
<li>
<a href = "timer_cputime_test03.m">timer_cputime_test03.m</a>,
test #3;
</li>
<li>
<a href = "timer_cputime_test04.m">timer_cputime_test04.m</a>,
test #4;
</li>
<li>
<a href = "timer_cputime_test_output.txt">timer_cputime_test_output.txt</a>,
output from the test;
</li>
</ul>
</p>
<p>
<b>ETIME_TEST</b> uses the ETIME routine:
<ul>
<li>
<a href = "timer_etime_test.m">timer_etime_test.m</a>,
the main body of the test;
</li>
<li>
<a href = "timer_etime_test01.m">timer_etime_test01.m</a>,
test #1;
</li>
<li>
<a href = "timer_etime_test02.m">timer_etime_test02.m</a>,
test #2;
</li>
<li>
<a href = "timer_etime_test03.m">timer_etime_test03.m</a>,
test #3;
</li>
<li>
<a href = "timer_etime_test04.m">timer_etime_test04.m</a>,
test #4;
</li>
<li>
<a href = "timer_etime_test_output.txt">timer_etime_test_output.txt</a>,
output from the test;
</li>
</ul>
</p>
<p>
<b>TICTOC_TEST</b> uses the TIC and TOC routine:
<ul>
<li>
<a href = "timer_tictoc_test.m">timer_tictoc_test.m</a>,
the main body of the test;
</li>
<li>
<a href = "timer_tictoc_test01.m">timer_tictoc_test01.m</a>,
test #1;
</li>
<li>
<a href = "timer_tictoc_test02.m">timer_tictoc_test02.m</a>,
test #2;
</li>
<li>
<a href = "timer_tictoc_test03.m">timer_tictoc_test03.m</a>,
test #3;
</li>
<li>
<a href = "timer_tictoc_test04.m">timer_tictoc_test04.m</a>,
test #4;
</li>
<li>
<a href = "timer_tictoc_test_output.txt">timer_tictoc_test_output.txt</a>,
output from the test;
</li>
</ul>
</p>
<p>
There are a few auxilliary routines you may need:
<ul>
<li>
<a href = "r8_huge.m">r8_huge.m</a>, returns a "huge" value;
</li>
<li>
<a href = "timestamp.m">timestamp.m</a>,
prints the YMDHMS date as a time stamp;
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../m_src.html">
the MATLAB source codes</a>.
</p>
<hr>
<i>
Last revised on 16 June 2006.
</i>
<!-- John Burkardt -->
</body>
</html>