summaryrefslogtreecommitdiff
path: root/lib/benchmark.rb
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-24 02:10:28 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-24 02:10:28 +0000
commit03fa0c49865c38b3fbe144712f189bec370350e5 (patch)
tree4005c5d9b8fa3245816437697741f181e277cc2c /lib/benchmark.rb
parent4d31df0342d16c9af47ec0dc2ff252887c2f6846 (diff)
lib/benchmark.rb (measure): reduce allocations as in r47260
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/benchmark.rb')
-rw-r--r--lib/benchmark.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/benchmark.rb b/lib/benchmark.rb
index eff6cb12ef..7c03c4a195 100644
--- a/lib/benchmark.rb
+++ b/lib/benchmark.rb
@@ -270,14 +270,22 @@ module Benchmark
STDOUT.sync = sync unless sync.nil?
end
+ # :stopdoc:
+ if defined?(Process::CLOCK_MONOTONIC)
+ BENCHMARK_CLOCK = Process::CLOCK_MONOTONIC
+ else
+ BENCHMARK_CLOCK = Process::CLOCK_REALTIME
+ end
+ # :startdoc:
+
#
# Returns the time used to execute the given block as a
# Benchmark::Tms object.
#
def measure(label = "") # :yield:
- t0, r0 = Process.times, Time.now
+ t0, r0 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
yield
- t1, r1 = Process.times, Time.now
+ t1, r1 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
Benchmark::Tms.new(t1.utime - t0.utime,
t1.stime - t0.stime,
t1.cutime - t0.cutime,
@@ -286,14 +294,6 @@ 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.
#