[R] Which system.time() component to use?
jholtman at gmail.com
Sun Feb 28 06:03:27 CET 2010
A lot depends on what you are trying to measure.
You should add the system and user CPU times to get a better idea of
the CPU utilization. For some classes of problems it might be good to
separate them if you were doing a lot of I/O or other system calls
that might be using time, but for 99% of the cases adding them is the
way to go.
You also want to look at elapsed times. If the script is CPU bound
the elapsed and total CPU times should be close. In the case that
Gabor gave of sleeping for 60 seconds, no CPU time was used, but it
was 60 seconds of elapsed time. If there is a big difference, it
might be due to a lot of I/O or possible paging if you did not have
On Sat, Feb 27, 2010 at 11:44 PM, Ravi Varadhan <rvaradhan at jhmi.edu> wrote:
> Thanks, Gabor. Your reply is helpful, but it still doesn't answer whether I should use the sum of the first two components of system.time (user + system CPU) or only the first one (user CPU).
> Ravi Varadhan, Ph.D.
> Assistant Professor,
> Division of Geriatric Medicine and Gerontology
> School of Medicine
> Johns Hopkins University
> Ph. (410) 502-2619
> email: rvaradhan at jhmi.edu
> ----- Original Message -----
> From: Gabor Grothendieck <ggrothendieck at gmail.com>
> Date: Saturday, February 27, 2010 9:47 pm
> Subject: Re: [R] Which system.time() component to use?
> To: Ravi Varadhan <rvaradhan at jhmi.edu>
> Cc: r-help at r-project.org
>> Try this:
>> > system.time(Sys.sleep(60))
>> user system elapsed
>> 0.00 0.00 60.05
>> > pt <- proc.time(); Sys.sleep(60); proc.time() - pt
>> user system elapsed
>> 0.00 0.00 60.01
>> On Sat, Feb 27, 2010 at 9:33 PM, Ravi Varadhan <rvaradhan at jhmi.edu> wrote:
>> > Hi,
>> > The `system.time(expr)' command provide 3 different times for
>> evaluating the expression `expr'; the first two are user and system
>> CPUs and the third one is total elapsed time. Suppose I want to
>> compare two different computational procedures for performing the same
>> task, which component of `system.time' is most meaningful in the sense
>> that it most accurately reflects the computational effort of the
>> algorithm, and does not depend upon the idiosyncrasies of the
>> operating system.
>> > I have always been using the first component of `system.time', which
>> is the user CPU. Should I use the sum of user and system CPU or is
>> the total elapsed time a better measure? I would appreciate UseR's
>> feedback on this.
>> > Thanks very much.
>> > Best,
>> > Ravi.
>> > ____________________________________________________________________
>> > Ravi Varadhan, Ph.D.
>> > Assistant Professor,
>> > Division of Geriatric Medicine and Gerontology
>> > School of Medicine
>> > Johns Hopkins University
>> > Ph. (410) 502-2619
>> > email: rvaradhan at jhmi.edu
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > PLEASE do read the posting guide
>> > and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help