measure(label = "")
private
Returns the time used to execute the given block as a Benchmark::Tms object. Takes label
option.
require 'benchmark'
n = 1000000
time = Benchmark.measure do
n.times { a = "1" }
end
puts time
Generates:
0.220000 0.000000 0.220000 ( 0.227313)
Show source
def measure(label = "")
t0, r0 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
t1, r1 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
Benchmark::Tms.new(t1.utime - t0.utime,
t1.stime - t0.stime,
t1.cutime - t0.cutime,
t1.cstime - t0.cstime,
r1 - r0,
label)
end