public
Created

Ruby Benchmark module: meanings of “user”, “system”, and “real”?

  • Download Gist
user_system_real.md
Markdown

Ruby Benchmark module: meanings of “user”, “system”, and “real”?

>> Benchmark.bm(7) { |b| b.report('Report:') { s = '' ; 10000.times { s += 'a' } }  }
             user     system      total        real
Report:  0.150000   0.010000   0.160000 (  0.156361)

These are the same times that the Unix time command or other typical benchmarking tools would report:

user: the amount of time spent executing userspace code (i.e.: your code),

system: the amount of time spent executing kernel code and

real: the "real" amount of time it took to execute the code (i.e. system + user + time spent waiting for I/O, network, disk, user input, etc.). Also known as "wallclock time".

Source

Also

Why real≠user+sys always

Keep in mind that "real" represents actual elapsed time, while user and sys values represent CPU execution time. As a result, on a multicore system, the user and/or sys time (as well as their sum) can actually exceed the real time. For example, on a java app I'm running for class I get this set of values:

real 1m47.363s
user 2m41.318s
sys 0m4.013s

Source

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.