Skip to content

Instantly share code, notes, and snippets.

@anildigital
Created September 20, 2011 18:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anildigital/1229896 to your computer and use it in GitHub Desktop.
Save anildigital/1229896 to your computer and use it in GitHub Desktop.
Ruby Benchmark module: meanings of “user”, “system”, and “real”?

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

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