Project

General

Profile

Feature #10165 » faster_benchmark_realtime_2.diff

phiggins (Pete Higgins), 08/24/2014 12:22 AM

View differences:

lib/benchmark.rb
label)
end
# :stopdoc:
if defined?(Process::CLOCK_MONOTONIC)
BENCHMARK_CLOCK = Process::CLOCK_MONOTONIC
else
BENCHMARK_CLOCK = Process::CLOCK_REALTIME
end
# :startdoc:
#
# Returns the elapsed real time used to execute the given block.
#
def realtime # :yield:
r0 = Time.now
r0 = Process.clock_gettime(BENCHMARK_CLOCK)
yield
Time.now - r0
Process.clock_gettime(BENCHMARK_CLOCK) - 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
(3-3/3)