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

后端 未结 5 1447
粉色の甜心
粉色の甜心 2020-12-04 11:03

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

The output I get for the call

system.time(myfunction())
         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-04 11:45

    Since those time variables are defined by your OS, you can retrieve information on how they are calculated by executing man time in your shell (on Unix):

    ...These statistics consist of (i) the elapsed real time between invocation and termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).

    The definition of the mentioned time variables can be found here:

    tms_utime User CPU time.

    tms_stime System CPU time.

    tms_cutime User CPU time of terminated child processes.

    tms_cstime System CPU time of terminated child processes.

    A a clarification of the differences between user and system time is described in daroczig's answer and elsewhere on SO:

    The tms_utime element is the amount of time spent executing your code, or the code in the C library. The tms_stime element is the amount of time spent in the kernel executing code on your behalf.

提交回复
热议问题