annotate scripts/miscellaneous/cputime.m @ 6156:a46f14cdbecd

[project @ 2006-11-13 19:20:23 by jwe]
author jwe
date Mon, 13 Nov 2006 19:20:23 +0000
parents 4c8a2e4e0717
children 93c65f2a5668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2314
diff changeset
1 ## Copyright (C) 1996, 1997 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
8 ## any later version.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 3301
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 3301
diff changeset
18 ## 02110-1301, USA.
1189
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
19
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
20 ## -*- texinfo -*-
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
21 ## @deftypefn {Function File} {[@var{total}, @var{user}, @var{system}] =} cputime ();
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
22 ## Return the CPU time used by your Octave session. The first output is
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
23 ## the total time spent executing your process and is equal to the sum of
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
24 ## second and third outputs, which are the number of CPU seconds spent
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
25 ## executing in user mode and the number of CPU seconds spent executing in
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
26 ## system mode, respectively. If your system does not have a way to report
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
27 ## CPU time usage, @code{cputime} returns 0 for each of its output values.
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
28 ## Note that because Octave used some CPU time to start, it is reasonable
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
29 ## to check to see if @code{cputime} works by checking to see if the total
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
30 ## CPU time used is nonzero.
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 2847
diff changeset
31 ## @end deftypefn
1189
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
32
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
33 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
34
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
35 function [total, user, system] = cputime ()
1189
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
36
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
37 if (nargin != 0)
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
38 warning ("cputime: ignoring extra arguments");
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
39 endif
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
40
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
41 resource_stats = getrusage ();
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
42
1383
d0bdfca51b42 [project @ 1995-09-13 08:16:39 by jwe]
jwe
parents: 1315
diff changeset
43 usr = resource_stats.utime;
d0bdfca51b42 [project @ 1995-09-13 08:16:39 by jwe]
jwe
parents: 1315
diff changeset
44 sys = resource_stats.stime;
1189
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
45
2017
1d831915c580 [project @ 1996-03-22 10:40:47 by jwe]
jwe
parents: 1887
diff changeset
46 user = usr.sec + usr.usec / 1e6;
1d831915c580 [project @ 1996-03-22 10:40:47 by jwe]
jwe
parents: 1887
diff changeset
47 system = sys.sec + sys.usec / 1e6;
1d831915c580 [project @ 1996-03-22 10:40:47 by jwe]
jwe
parents: 1887
diff changeset
48 total = user + system;
1189
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
49
ccf2867d8a80 [project @ 1995-03-30 20:25:43 by jwe]
jwe
parents:
diff changeset
50 endfunction