5633
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} tic () |
|
22 ## @deftypefnx {Function File} {} toc () |
|
23 ## These functions set and check a wall-clock timer. For example, |
|
24 ## |
|
25 ## @example |
|
26 ## tic (); |
|
27 ## # many computations later... |
|
28 ## elapsed_time = toc (); |
|
29 ## @end example |
|
30 ## |
|
31 ## @noindent |
|
32 ## will set the variable @code{elapsed_time} to the number of seconds since |
|
33 ## the most recent call to the function @code{tic}. |
|
34 ## |
|
35 ## Nested timing with @code{tic} and @code{toc} is not supported. |
|
36 ## Therefore @code{toc} will always return the elapsed time from the most |
|
37 ## recent call to @code{tic}. |
|
38 ## |
|
39 ## If you are more interested in the CPU time that your process used, you |
|
40 ## should use the @code{cputime} function instead. The @code{tic} and |
|
41 ## @code{toc} functions report the actual wall clock time that elapsed |
|
42 ## between the calls. This may include time spent processing other jobs or |
|
43 ## doing nothing at all. For example, |
|
44 ## |
|
45 ## @example |
|
46 ## @group |
|
47 ## tic (); sleep (5); toc () |
|
48 ## @result{} 5 |
|
49 ## t = cputime (); sleep (5); cputime () - t |
|
50 ## @result{} 0 |
|
51 ## @end group |
|
52 ## @end example |
|
53 ## |
|
54 ## @noindent |
|
55 ## (This example also illustrates that the CPU timer may have a fairly |
|
56 ## coarse resolution.) |
|
57 ## @end deftypefn |
|
58 |
|
59 ## Author: jwe |
|
60 |
|
61 function tic () |
|
62 |
|
63 if (nargin != 0) |
|
64 warning ("tic: ignoring extra arguments"); |
|
65 endif |
|
66 |
|
67 global __tic_toc_timestamp__; |
|
68 |
|
69 __tic_toc_timestamp__ = clock (); |
|
70 |
|
71 endfunction |