From 249bd1ed2a00c9c3defdd09224b22a6691f73789 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 24 Aug 2014 02:03:06 +0000 Subject: lib/benchmark.rb: speedup by reducing allocations * lib/benchmark.rb (module Benchmark): define BENCHMARK_CLOCK (realtime): use Process.clock_gettime(BENCHMARK_CLOCK) [Feature #10165] * test/benchmark/test_benchmark.rb (test_realtime_output): new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/benchmark.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/benchmark.rb b/lib/benchmark.rb index bd3b07284f..eff6cb12ef 100644 --- a/lib/benchmark.rb +++ b/lib/benchmark.rb @@ -286,13 +286,21 @@ module Benchmark 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 -- cgit v1.2.3