home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / miscellaneous / cputime.m < prev    next >
Text File  |  1999-10-20  |  2KB  |  51 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. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {[@var{total}, @var{user}, @var{system}] =} cputime ();
  22. ## Return the CPU time used by your Octave session.  The first output is
  23. ## the total time spent executing your process and is equal to the sum of
  24. ## second and third outputs, which are the number of CPU seconds spent
  25. ## executing in user mode and the number of CPU seconds spent executing in
  26. ## system mode, respectively.  If your system does not have a way to report
  27. ## CPU time usage, @code{cputime} returns 0 for each of its output values.
  28. ## Note that because Octave used some CPU time to start, it is reasonable
  29. ## to check to see if @code{cputime} works by checking to see if the total
  30. ## CPU time used is nonzero.
  31. ## @end deftypefn
  32.  
  33. ## Author: jwe
  34.  
  35. function [total, user, system] = cputime ()
  36.  
  37.   if (nargin != 0)
  38.     warning ("cputime: ignoring extra arguments");
  39.   endif
  40.  
  41.   resource_stats = getrusage ();
  42.  
  43.   usr = resource_stats.utime;
  44.   sys = resource_stats.stime;
  45.  
  46.   user = usr.sec + usr.usec / 1e6;
  47.   system = sys.sec + sys.usec / 1e6;
  48.   total = user + system;
  49.  
  50. endfunction
  51.