5596
|
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} {} etime (@var{t1}, @var{t2}) |
|
22 ## Return the difference (in seconds) between two time values returned from |
|
23 ## @code{clock}. For example: |
|
24 ## |
|
25 ## @example |
|
26 ## t0 = clock (); |
|
27 ## # many computations later... |
|
28 ## elapsed_time = etime (clock (), t0); |
|
29 ## @end example |
|
30 ## |
|
31 ## @noindent |
|
32 ## will set the variable @code{elapsed_time} to the number of seconds since |
|
33 ## the variable @code{t0} was set. |
5642
|
34 ## @seealso{tic, toc, clock, cputime} |
5596
|
35 ## @end deftypefn |
|
36 |
|
37 ## Author: jwe |
|
38 |
|
39 function secs = etime (t1, t0) |
|
40 |
|
41 if (nargin != 2) |
6046
|
42 print_usage (); |
5596
|
43 endif |
|
44 |
5660
|
45 [d1, s1] = datenum (t1); |
|
46 [d0, s0] = datenum (t0); |
5596
|
47 |
5660
|
48 secs = s1 - s0; |
5596
|
49 |
|
50 endfunction |
5660
|
51 |
|
52 %!assert(etime([1900,12,31,23,59,59],[1901,1,1,0,0,0]),-1) |
|
53 %!assert(etime([1900,2,28,23,59,59],[1900,3,1,0,0,0]),-1) |
|
54 %!assert(etime([2000,2,28,23,59,59],[2000,3,1,0,0,0]),-86401) |
|
55 %!assert(etime([1996,2,28,23,59,59],[1996,3,1,0,0,0]),-86401) |
|
56 %!test |
|
57 %! t1 = [1900,12,31,23,59,59; 1900,2,28,23,59,59]; |
|
58 %! t2 = [1901,1,1,0,0,0; 1900,3,1,0,0,0]; |
|
59 %! assert(etime(t2, t1), [1;1]); |