Class: ThreadsafeBenchmark::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/threadsafe_benchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(width = 0, fmtstr = nil) ⇒ Report

Returns a new instance of Report.



14
15
16
# File 'lib/threadsafe_benchmark.rb', line 14

def initialize(width = 0, fmtstr = nil)
  @width, @fmtstr = width, fmtstr
end

Instance Method Details

#item(label = "", *fmt, &blk) ⇒ Object Also known as: report

:yield:



18
19
20
21
22
23
# File 'lib/threadsafe_benchmark.rb', line 18

def item(label = "", *fmt, &blk) # :yield:
  Thread.current["io"] << label.ljust(@width)
  res = Benchmark::measure(&blk)
  Thread.current["io"] << res.format(@fmtstr, *fmt)
  res
end