Project

General

Profile

Feature #10165 » faster_benchmark_realtime.diff

phiggins (Pete Higgins), 08/23/2014 08:59 PM

View differences:

lib/benchmark.rb
# Returns the elapsed real time used to execute the given block.
#
def realtime # :yield:
r0 = Time.now
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Time.now - r0
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
end
module_function :benchmark, :measure, :realtime, :bm, :bmbm
test/benchmark/test_benchmark.rb
t.add! { sleep 0.1 }
assert_not_equal(0, t.real)
end
def test_realtime_output
realtime = Benchmark.realtime { sleep 0.001 }
assert_in_delta 0.001, realtime
end
end
(2-2/3)