mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/benchmark.rb: just use Process::CLOCK_MONOTONIC
Assume Process::CLOCK_MONOTONIC exists (possibly emulated) and there is no need to bloat our code by defining a compatibility constant. * lib/benchmark.rb: just use Process::CLOCK_MONOTONIC [ruby-core:69390] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fd4ec2bc90
commit
cb1affb478
2 changed files with 9 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Jun 2 09:04:14 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* lib/benchmark.rb: just use Process::CLOCK_MONOTONIC
|
||||
[ruby-core:69390]
|
||||
|
||||
Mon Jun 1 22:01:27 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/mkmf.rb (pkg_config): split --libs if --libs-only-l option
|
||||
|
|
|
@ -270,15 +270,6 @@ module Benchmark
|
|||
STDOUT.sync = sync unless sync.nil?
|
||||
end
|
||||
|
||||
# :stopdoc:
|
||||
case
|
||||
when 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. Takes +label+ option.
|
||||
|
@ -297,9 +288,9 @@ module Benchmark
|
|||
# 0.220000 0.000000 0.220000 ( 0.227313)
|
||||
#
|
||||
def measure(label = "") # :yield:
|
||||
t0, r0 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
|
||||
t0, r0 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
yield
|
||||
t1, r1 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
|
||||
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,
|
||||
|
@ -312,9 +303,9 @@ module Benchmark
|
|||
# Returns the elapsed real time used to execute the given block.
|
||||
#
|
||||
def realtime # :yield:
|
||||
r0 = Process.clock_gettime(BENCHMARK_CLOCK)
|
||||
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
yield
|
||||
Process.clock_gettime(BENCHMARK_CLOCK) - r0
|
||||
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
|
||||
end
|
||||
|
||||
module_function :benchmark, :measure, :realtime, :bm, :bmbm
|
||||
|
|
Loading…
Add table
Reference in a new issue