diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-28 06:09:46 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-28 06:09:46 +0000 |
commit | 4870feb31a6625dcbf8817ccf16294bb3f3737e1 (patch) | |
tree | 1fa4ee51e75c71fe786b1c90e76b1e2f577c5a3a /lib/benchmark.rb | |
parent | 565336acca867889a43b8a2f8331a253d97dee0c (diff) |
* lib/benchmark.rb: merge eregon/benchmark.
https://github.com/eregon/ruby/tree/benchmark
patched by Benoit Daloze. [ruby-core:37593] [Bug #4940]
* lib/benchmark (Benchmark#bmbm): bmbm should be consistent with bm
for the return value.
* test/benchmark: remove preemptive test instead of skipping
I removed the preemptive test I wrote for Feature #4197.
I'll add it back when the implementation will be able to satisfy it.
* lib/benchmark (Benchmark#bmbm): remove useless explicit call,
#format is an alias of #to_s test/benchmark: add a test for
format of long time.
* lib/benchmark: fix label width: always add 1 to ensure there is a
space delimiter even with times over 100s
When I asked for Feature #4197, I wanted to make delimiting spaces
consistent for #bm and #bmbm.
But with times over 100s, the output contains no space between the
label and the first time (user).
Now both ensure there is always a space, even if that means 3 spaces
with times under 10s (because it is formatted as %10.6f)
* test/benchmark: let labels be a constant
lib/benchmark (Benchmark#realtime): avoid creating an unused Proc
lib/benchmark (Benchmark#benchmark): use ensure clause to restore
STDOUT.sync, as in #bmbm
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/benchmark.rb')
-rw-r--r-- | lib/benchmark.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/benchmark.rb b/lib/benchmark.rb index 5ca9db1661..6a00da1359 100644 --- a/lib/benchmark.rb +++ b/lib/benchmark.rb @@ -167,6 +167,7 @@ module Benchmark sync = STDOUT.sync STDOUT.sync = true label_width ||= 0 + label_width += 1 format ||= FORMAT print ' '*label_width + caption report = Report.new(label_width, format) @@ -174,8 +175,9 @@ module Benchmark Array === results and results.grep(Tms).each {|t| print((labels.shift || t.label || "").ljust(label_width), t.format(format)) } - STDOUT.sync = sync report.list + ensure + STDOUT.sync = sync unless sync.nil? end @@ -244,7 +246,7 @@ module Benchmark def bmbm(width = 0, &blk) # :yield: job job = Job.new(width) yield(job) - width = job.width + width = job.width + 1 sync = STDOUT.sync STDOUT.sync = true @@ -263,7 +265,7 @@ module Benchmark job.list.map { |label,item| GC.start print label.ljust(width) - Benchmark.measure(&item).tap { |res| print res.format } + Benchmark.measure(label, &item).tap { |res| print res } } ensure STDOUT.sync = sync unless sync.nil? @@ -288,7 +290,7 @@ module Benchmark # # Returns the elapsed real time used to execute the given block. # - def realtime(&blk) # :yield: + def realtime # :yield: r0 = Time.now yield Time.now - r0 |