# HG changeset patch # User dbateman # Date 1193053959 0 # Node ID 271fa61d8faee877b49b8ce36456c80fd333ed1f # Parent 0064f7d6a4517413cfb0315d36d44b5c3b6c2c13 [project @ 2007-10-22 11:52:38 by dbateman] diff -r 0064f7d6a451 -r 271fa61d8fae scripts/ChangeLog --- a/scripts/ChangeLog Sun Oct 21 20:28:03 2007 +0000 +++ b/scripts/ChangeLog Mon Oct 22 11:52:39 2007 +0000 @@ -1,3 +1,9 @@ +2007-10-22 David Bateman + + * miscellaneous/cputime.m, time/tic.m, time/toc.m: Delete. + * miscellaneous/Makefile.in (SOURCES): remove cputim.m + * time/Makefile.in (SOURCES): Remov tic.m and toc.m + 2007-10-19 Kai Habel * plot/contourf.m: New function. diff -r 0064f7d6a451 -r 271fa61d8fae scripts/miscellaneous/Makefile.in --- a/scripts/miscellaneous/Makefile.in Sun Oct 21 20:28:03 2007 +0000 +++ b/scripts/miscellaneous/Makefile.in Mon Oct 22 11:52:39 2007 +0000 @@ -34,7 +34,7 @@ INSTALL_DATA = @INSTALL_DATA@ SOURCES = ans.m bincoeff.m bug_report.m bunzip2.m cast.m comma.m \ - compare_versions.m computer.m copyfile.m cputime.m \ + compare_versions.m computer.m copyfile.m \ delete.m dir.m doc.m dos.m dump_prefs.m \ fileattrib.m fileparts.m flops.m fullfile.m getfield.m gunzip.m \ gzip.m inputname.m ismac.m ispc.m isunix.m license.m list_primes.m ls.m \ diff -r 0064f7d6a451 -r 271fa61d8fae scripts/miscellaneous/cputime.m --- a/scripts/miscellaneous/cputime.m Sun Oct 21 20:28:03 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -## Copyright (C) 1995, 1996, 1997, 1999, 2005, 2007 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{total}, @var{user}, @var{system}] =} cputime (); -## Return the CPU time used by your Octave session. The first output is -## the total time spent executing your process and is equal to the sum of -## second and third outputs, which are the number of CPU seconds spent -## executing in user mode and the number of CPU seconds spent executing in -## system mode, respectively. If your system does not have a way to report -## CPU time usage, @code{cputime} returns 0 for each of its output values. -## Note that because Octave used some CPU time to start, it is reasonable -## to check to see if @code{cputime} works by checking to see if the total -## CPU time used is nonzero. -## @end deftypefn - -## Author: jwe - -function [total, user, system] = cputime () - - if (nargin != 0) - warning ("cputime: ignoring extra arguments"); - endif - - resource_stats = getrusage (); - - usr = resource_stats.utime; - sys = resource_stats.stime; - - user = usr.sec + usr.usec / 1e6; - system = sys.sec + sys.usec / 1e6; - total = user + system; - -endfunction diff -r 0064f7d6a451 -r 271fa61d8fae scripts/time/Makefile.in --- a/scripts/time/Makefile.in Sun Oct 21 20:28:03 2007 +0000 +++ b/scripts/time/Makefile.in Mon Oct 22 11:52:39 2007 +0000 @@ -34,7 +34,7 @@ SOURCES = asctime.m calendar.m clock.m ctime.m date.m datenum.m \ datestr.m datevec.m eomday.m etime.m is_leap_year.m now.m \ - tic.m toc.m weekday.m + weekday.m DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES)) diff -r 0064f7d6a451 -r 271fa61d8fae scripts/time/tic.m --- a/scripts/time/tic.m Sun Oct 21 20:28:03 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -## Copyright (C) 1996, 1997, 2006, 2007 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} tic () -## @deftypefnx {Function File} {} toc () -## Set or check a wall-clock timer. Calling @code{tic} without an -## output argument sets the timer. Subsequent calls to @code{toc} -## return the number of seconds since the timer was set. For example, -## -## @example -## tic (); -## # many computations later... -## elapsed_time = toc (); -## @end example -## -## @noindent -## will set the variable @code{elapsed_time} to the number of seconds since -## the most recent call to the function @code{tic}. -## -## If called with one output argument then this function returns a scalar -## of type @code{uint64} and the wall-clock timer is not started. -## -## @example -## @group -## t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6 -## @result{} 5 -## @end group -## @end example -## -## Nested timing with @code{tic} and @code{toc} is not supported. -## Therefore @code{toc} will always return the elapsed time from the most -## recent call to @code{tic}. -## -## If you are more interested in the CPU time that your process used, you -## should use the @code{cputime} function instead. The @code{tic} and -## @code{toc} functions report the actual wall clock time that elapsed -## between the calls. This may include time spent processing other jobs or -## doing nothing at all. For example, -## -## @example -## @group -## tic (); sleep (5); toc () -## @result{} 5 -## t = cputime (); sleep (5); cputime () - t -## @result{} 0 -## @end group -## @end example -## -## @noindent -## (This example also illustrates that the CPU timer may have a fairly -## coarse resolution.) -## @end deftypefn - -## Author: jwe - -function ret = tic () - - if (nargin != 0) - warning ("tic: ignoring extra arguments"); - endif - - if (nargout == 1) - ret = uint64 (time () * 1e6); - else - global __tic_toc_timestamp__; - __tic_toc_timestamp__ = clock (); - endif - -endfunction diff -r 0064f7d6a451 -r 271fa61d8fae scripts/time/toc.m --- a/scripts/time/toc.m Sun Oct 21 20:28:03 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -## Copyright (C) 1996, 1997, 2006, 2007 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {} toc () -## See tic. -## @end deftypefn - -## Author: jwe - -function secs = toc () - - if (nargin != 0) - warning ("toc: ignoring extra arguments"); - endif - - global __tic_toc_timestamp__ = -1; - - if (__tic_toc_timestamp__ < 0) - warning ("toc called before timer set"); - secs0 = []; - else - secs0 = etime (clock (), __tic_toc_timestamp__); - if (nargout != 0) - secs = secs0; - else - printf ("Elapsed time is %f seconds.\n", secs0); - endif - endif - -endfunction diff -r 0064f7d6a451 -r 271fa61d8fae src/ChangeLog --- a/src/ChangeLog Sun Oct 21 20:28:03 2007 +0000 +++ b/src/ChangeLog Mon Oct 22 11:52:39 2007 +0000 @@ -1,3 +1,8 @@ +2007-10-22 David Bateman + + * data.cc (Ftic, Ftoc, Fcputime): New builtin versions of the + benchmarking functions for speed. + 2007-10-19 Kai Habel * DLD-FUNCTIONS/__contourc__.cc (add_point): Rename from diff -r 0064f7d6a451 -r 271fa61d8fae src/data.cc --- a/src/data.cc Sun Oct 21 20:28:03 2007 +0000 +++ b/src/data.cc Mon Oct 22 11:52:39 2007 +0000 @@ -47,6 +47,7 @@ #include "pt-mat.h" #include "utils.h" #include "variables.h" +#include "pager.h" #define ANY_ALL(FCN) \ \ @@ -2963,6 +2964,180 @@ BINARY_OP_DEFUN_BODY (op_el_or); } +static double __tic_toc_timestamp__ = -1.0; + +DEFUN (tic, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} tic ()\n\ +@deftypefnx {Built-in Function} {} toc ()\n\ +Set or check a wall-clock timer. Calling @code{tic} without an\n\ +output argument sets the timer. Subsequent calls to @code{toc}\n\ +return the number of seconds since the timer was set. For example,\n\ +\n\ +@example\n\ +tic ();\n\ +# many computations later...\n\ +elapsed_time = toc ();\n\ +@end example\n\ +\n\ +@noindent\n\ +will set the variable @code{elapsed_time} to the number of seconds since\n\ +the most recent call to the function @code{tic}.\n\ +\n\ +If called with one output argument then this function returns a scalar\n\ +of type @code{uint64} and the wall-clock timer is not started.\n\ +\n\ +@example\n\ +@group\n\ +t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6\n\ + @result{} 5\n\ +@end group\n\ +@end example\n\ +\n\ +Nested timing with @code{tic} and @code{toc} is not supported.\n\ +Therefore @code{toc} will always return the elapsed time from the most\n\ +recent call to @code{tic}.\n\ +\n\ +If you are more interested in the CPU time that your process used, you\n\ +should use the @code{cputime} function instead. The @code{tic} and\n\ +@code{toc} functions report the actual wall clock time that elapsed\n\ +between the calls. This may include time spent processing other jobs or\n\ +doing nothing at all. For example,\n\ +\n\ +@example\n\ +@group\n\ +tic (); sleep (5); toc ()\n\ + @result{} 5\n\ +t = cputime (); sleep (5); cputime () - t\n\ + @result{} 0\n\ +@end group\n\ +@end example\n\ +\n\ +@noindent\n\ +(This example also illustrates that the CPU timer may have a fairly\n\ +coarse resolution.)\n\ +@end deftypefn") +{ + octave_value retval; + int nargin = args.length (); + + if (nargin != 0) + warning ("tic: ignoring extra arguments"); + + if (nargout > 0) + retval = static_cast (static_cast (octave_time ()) * 1.0e6); + else + __tic_toc_timestamp__= static_cast(octave_time ()); + + return retval; +} + +DEFUN (toc, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} toc ()\n\ +See tic.\n\ +@end deftypefn") +{ + double sec = static_cast(octave_time ()); + octave_value retval; + int nargin = args.length (); + + if (nargin != 0) + warning ("tic: ignoring extra arguments"); + + if (__tic_toc_timestamp__ < 0) + { + warning ("toc called before timer set"); + if (nargout > 0) + retval = Matrix(); + } + else if (nargout > 0) + retval = sec - __tic_toc_timestamp__; + else + octave_stdout << "Elapsed time is " << sec - __tic_toc_timestamp__ + << " seconds.\n"; + + return retval; +} + +DEFUN (cputime, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\ +Return the CPU time used by your Octave session. The first output is\n\ +the total time spent executing your process and is equal to the sum of\n\ +second and third outputs, which are the number of CPU seconds spent\n\ +executing in user mode and the number of CPU seconds spent executing in\n\ +system mode, respectively. If your system does not have a way to report\n\ +CPU time usage, @code{cputime} returns 0 for each of its output values.\n\ +Note that because Octave used some CPU time to start, it is reasonable\n\ +to check to see if @code{cputime} works by checking to see if the total\n\ +CPU time used is nonzero.\n\ +@end deftypefn") +{ + octave_value_list retval; + int nargin = args.length (); + double usr = 0.0; + double sys = 0.0; + + if (nargin != 0) + warning ("tic: ignoring extra arguments"); + +#if defined (HAVE_GETRUSAGE) + + struct rusage ru; + + getrusage (RUSAGE_SELF, &ru); + + usr = static_cast (ru.ru_utime.tv_sec) + + static_cast (ru.ru_utime.tv_usec) * 1e-6; + + sys = static_cast (ru.ru_stime.tv_sec) + + static_cast (ru.ru_stime.tv_usec) * 1e-6; + +#elif defined (HAVE_TIMES) && defined (HAVE_SYS_TIMES_H) + + struct tms t; + + times (&t); + + unsigned long ticks; + unsigned long seconds; + unsigned long fraction; + + ticks = t.tms_utime + t.tms_cutime; + fraction = ticks % HZ; + seconds = ticks / HZ; + + usr = static_cast (seconds) + static_cast(fraction) / + static_cast(HZ); + + ticks = t.tms_stime + t.tms_cstime; + fraction = ticks % HZ; + seconds = ticks / HZ; + + sys = static_cast (seconds) + static_cast(fraction) / + static_cast(HZ); + +#elif defined (__WIN32__) + HANDLE hProcess = GetCurrentProcess (); + FILETIME ftCreation, ftExit, ftUser, ftKernel; + GetProcessTimes (hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser); + + int64_t itmp = *(reinterpret_cast (&ftUser)); + usr = static_cast (itmp) * 1e-1; + + itmp = *(reinterpret_cast (&ftKernel)); + sys = static_cast (itmp) * 1e-1; + +#endif + + retval (2) = sys; + retval (1) = usr; + retval (0) = sys + usr; + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***