home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / miscellaneous / etime.m < prev    next >
Text File  |  1998-11-10  |  2KB  |  64 lines

  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, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: etime (t1, t0)
  21. ##
  22. ## Return the difference between t1 and t0 in seconds.  The arguments
  23. ## are expected to be vectors in the form returned by clock ().
  24. ##
  25. ## See also: tic, toc, clock, cputime
  26.  
  27. ## Author: jwe
  28.  
  29. function secs = etime (t1, t0)
  30.  
  31.   if (nargin != 2)
  32.     usage ("etime (t1, t0)");
  33.   endif
  34.  
  35.   if (is_vector (t1) && length (t1) == 6 && is_vector (t0) && length (t0) == 6)
  36.  
  37.     if (t1 (1) != t0 (1))
  38.       error ("etime: can't handle timings over year boundaries yet");
  39.     endif
  40.  
  41.     ## XXX FIXME XXX -- could check here to ensure that t1 and t0 really do
  42.     ## make sense as vectors returned from clock().
  43.  
  44.     days_in_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  45.  
  46.     if (is_leap_year (t1 (1)))
  47.       days_in_months (2) = days_in_months (2) + 1;
  48.     endif
  49.  
  50.     d1 = sum (days_in_months (1:(t1 (2) - 1))) + t1 (3);
  51.     d0 = sum (days_in_months (1:(t0 (2) - 1))) + t0 (3);
  52.  
  53.     s1 = 86400 * d1 + 3600 * t1 (4) + 60 * t1 (5) + t1 (6);
  54.     s0 = 86400 * d0 + 3600 * t0 (4) + 60 * t0 (5) + t0 (6);
  55.  
  56.     secs = s1 - s0;
  57.  
  58.   else
  59.     error ("etime: args are not 6-element vectors");
  60.   endif
  61.  
  62.  
  63. endfunction
  64.