Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are 'user' and 'system' times measuring in R system.time(exp) output?

Tags:

time

r

I am using system.time(expression) to measure execution time for an R function.

The output I get for the call

system.time(myfunction()) 

is:

    user  system elapsed      117.36    5.65  127.86 

What does 'user' and 'system' measure?

like image 553
cfort Avatar asked Apr 16 '11 19:04

cfort


People also ask

What does system time do in R?

Sys. time returns an absolute date-time value which can be converted to various time zones and may return different days. Sys. Date returns the current day in the current time zone.

What is the unit of system time in R?

The system. time() function is one of the tools that we can use to estimate how long it takes for a code to execute. Its output gives three values: user, system, and elapsed time in seconds.

How to measure time of a function in R?

To measure execution time of R code, we can use Sys. time function. Put it before and after the code and take difference of it to get the execution time of code.

Which command is used to get the system time in R?

proc. time , time which is for time series. Sys. time to get the current date & time.


2 Answers

This is discussed in ?proc.time (system.time() returns an object of class "proc.time"):

Details:       ‘proc.time’ returns five elements for backwards compatibility, but      its ‘print’ method prints a named vector of length 3.  The first      two entries are the total user and system CPU times of the current      R process and any child processes on which it has waited, and the      third entry is the ‘real’ elapsed time since the process was      started. 

....and

Value:  ....       The definition of ‘user’ and ‘system’ times is from your OS.      Typically it is something like       _The ‘user time’ is the CPU time charged for the execution of user      instructions of the calling process. The ‘system time’ is the CPU      time charged for execution by the system on behalf of the calling      process._ 
like image 61
Gavin Simpson Avatar answered Oct 03 '22 08:10

Gavin Simpson


The clearest explanation I've ever read on the difference between user and system elapsed time was provided by William Dunlap on [R-help]:

"User CPU time" gives the CPU time spent by the current process (i.e., the current R session) and "system CPU time" gives the CPU time spent by the kernel (the operating system) on behalf of the current process. The operating system is used for things like opening files, doing input or output, starting other processes, and looking at the system clock: operations that involve resources that many processes must share.

Although ?proc.time returns something similar, this description was a lot easier to understand for me.

like image 20
daroczig Avatar answered Oct 03 '22 06:10

daroczig