зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
4d31df0342
Коммит
03fa0c4986
|
@ -1,3 +1,7 @@
|
|||
Sun Aug 24 11:09:29 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* lib/benchmark.rb (measure): reduce allocations as in r47260
|
||||
|
||||
Sun Aug 24 10:35:54 2014 Pete Higgins <pete@peterhiggins.org>
|
||||
|
||||
* lib/benchmark.rb (module Benchmark): define BENCHMARK_CLOCK
|
||||
|
|
|
@ -270,22 +270,6 @@ module Benchmark
|
|||
STDOUT.sync = sync unless sync.nil?
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the time used to execute the given block as a
|
||||
# Benchmark::Tms object.
|
||||
#
|
||||
def measure(label = "") # :yield:
|
||||
t0, r0 = Process.times, Time.now
|
||||
yield
|
||||
t1, r1 = Process.times, Time.now
|
||||
Benchmark::Tms.new(t1.utime - t0.utime,
|
||||
t1.stime - t0.stime,
|
||||
t1.cutime - t0.cutime,
|
||||
t1.cstime - t0.cstime,
|
||||
r1 - r0,
|
||||
label)
|
||||
end
|
||||
|
||||
# :stopdoc:
|
||||
if defined?(Process::CLOCK_MONOTONIC)
|
||||
BENCHMARK_CLOCK = Process::CLOCK_MONOTONIC
|
||||
|
@ -294,6 +278,22 @@ module Benchmark
|
|||
end
|
||||
# :startdoc:
|
||||
|
||||
#
|
||||
# Returns the time used to execute the given block as a
|
||||
# Benchmark::Tms object.
|
||||
#
|
||||
def measure(label = "") # :yield:
|
||||
t0, r0 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
|
||||
yield
|
||||
t1, r1 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
|
||||
Benchmark::Tms.new(t1.utime - t0.utime,
|
||||
t1.stime - t0.stime,
|
||||
t1.cutime - t0.cutime,
|
||||
t1.cstime - t0.cstime,
|
||||
r1 - r0,
|
||||
label)
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the elapsed real time used to execute the given block.
|
||||
#
|
||||
|
|
Загрузка…
Ссылка в новой задаче