Jeroen Demeyer on Tue, 04 Apr 2006 16:22:07 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: elapsed time and system command


On Mon, Apr 03, 2006 at 03:46:43PM +0200, Bill Allombert wrote:
> On Sun, Apr 02, 2006 at 07:19:35AM +0000, cino hilliard wrote:
> > The timing functions # and ## do not account for the time taken by calls to 
> > external objects.
> > For example,
> > 
> > (01:06) gp > #
> >   timer = 1 (on)
> > (01:05) gp > t(n) = for(x=1,n,write("testtimer.txt","12345678901"))
> > (01:07) gp > t(100000)
> > time = 10,891 ms.
> > (01:08) gp > ##
> >  ***   last result computed in 10,891 ms.
> > 
> > Actually took 50 sec.
> > 
> > This has been the case for some time and applies to system commands also.
> 
> Actually, PARI support three timing functions, times, ftime and
> getrusage, getrusage being the default because this is the most reliable
> and reproducible. getrusage report user time, not system or
> wallclock time.

I'm not sure whether this is relevant to the original poster,
but getrusage() can report CPU time of the current process, as
well as the CPU time of its child processes.  This depends on the first
parameter being GETRUSAGE_SELF or GETRUSAGE_CHILDREN.  You could add
these to get "total CPU time".

I remember a short discussion with Bill, and he mentioned that this
would also count CPU time in GP's help system (which can spawn child
processes).  This is true, but I think this is only a minor caveat.

PS: My man page says in ftime(3):
This  function  is  obsolete. Don't use it. If the time in seconds
suffices, time(2) can be used; gettimeofday(2) gives microseconds;


Jeroen