Create a gist now

Instantly share code, notes, and snippets.

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

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

>> { |b|'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".



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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment