summaryrefslogtreecommitdiff
path: root/lib/benchmark.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/benchmark.rb')
-rw-r--r--lib/benchmark.rb10
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