annotate scripts/time/tic.m @ 6909:fc55a5e1760b ss-2-9-14

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