[R] sys.time question - how to improve R performance

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 26 16:26:19 CEST 2008

On Sat, 26 Apr 2008, Jiří Voller wrote:

> Dear R-users,
> I run my program a difference between sys.times is as follows:
> user   system  elapsed
> 60167.53  2848.75 63278.93
> I am quite puzzled how it may happen that  system time is so much shorter
> than user time, I have 2 core computer most of the time (90%) I was not
> doing anything else with the computer. What could be the reason of such a
> difference? I switched off file indexing and all other resident
> programs...... My program include writing output into a file - could that be
> the reason?

First, do you mean system.time()?  Its help page refers you to ?proc.time, 
which says:

      An object of class '"proc_time"' which is a numeric vector of
      length 5, containing the user, system, and total elapsed times for
      the currently running R process, and the cumulative sum of user
      and system times of any child processes spawned by it on which it
      has waited.  (The 'print' method combines the child times with
      those of the main process.)

and it seems you don't know those terms.  At any given time a CPU is 
running a task for a process, it is either in a system call or in user 
code (R itself or a package).  This is recorded every once in a while (a 
few ms) and totalled.  So your process spent 2848s in system calls.
The elapsed time is a little more than the sum of the user and system 
times, as your R session was not running 100% of the time.

You didn't even tell us your OS (see the posting guide) nor your 
background .  On a Unix-alike look at the man pages for time and times.
E.g. mine says

   The tms_utime field contains the CPU time spent executing instructions
   of the calling process.  The tms_stime field contains the CPU time
   spent in the system while executing tasks on behalf of the calling process.

> Thanks for your replies.
> -- 
> --------------------------------------------------------------------------------------------
> Ji?? Voller
> Laboratory of Growth Regulators
> Palack? University & Institute of Experimental Botany AS CR
> ?lechtitel? 11, 783 71 Olomouc
> Czech Republic
> http://rustreg.upol.cz
> landline: +420-585-634-855
> cell: +420-737-520-506
> fax: +420-585-634-870
> ----------------------------------------------------------------------------------------------
> 	[[alternative HTML version deleted]]

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list