From sfalcon at fhcrc.org  Mon May 15 01:06:20 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Sun, 14 May 2006 16:06:20 -0700
Subject: [Rd] Suggestion for system.time()
In-Reply-To: <20060514202944.GA28762@alcyon.progiciels-bpi.ca>
	(=?iso-8859-1?Q?Fran=E7ois?= Pinard's message of "Sun,
	14 May 2006 16:29:44 -0400")
References: <20060514140852.GA8854@phenix.sram.qc.ca>
	<m21wuwqtxh.fsf@ziti.local>
	<20060514202944.GA28762@alcyon.progiciels-bpi.ca>
Message-ID: <m2wtcop5oz.fsf@ziti.local>

Fran?ois Pinard <pinard at iro.umontreal.ca> writes:

> [Seth Falcon]
>>Here's a function you could try.  It names the result as you
>>suggested.  It also can be nested, which system.time cannot, because
>>it uses on.exit without specifying add=TRUE.
>
> Thanks, Seth.  Your code could be useful, I'm saving it. :-)

You make it sound like that code is going to mature like a wine.  I'd
say, if it isn't useful now, it will be less useful later, but hey,
disk space is cheap :-D

> Just to be clear, my suggestion was more thought as a small benefit
> for the community of R users, rather than for myself alone.

That's what I understood.  I bothered to post some code because I
agree and saw a couple of small ways to improve system.time: add
names, allow nesting, and compute the time once instead of twice[*].
Perhaps others will agree and consider a change.

Best,

+ seth


[*] system.time computes the elapsed time twice: once when running the
on.exit hook, which gets called explicitly (!), and once for the
return value.  Here's the relevant lines:

    on.exit(cat("Timing stopped at:", proc.time() - time, "\n"))  ## once
    eval(expr, envir = loc.frame)
    new.time <- proc.time()
    on.exit()
    new.time - time                                               ## twice



[Rd] Suggestion for system.time()
Seth Falcon