Class: Benchmark::Report
- Inherits:
-
Object
- Object
- Benchmark::Report
- Defined in:
- lib/benchmark.rb,
lib/railsbench/benchmark.rb
Overview
This class is used by the Benchmark.benchmark and Benchmark.bm methods. It is of little direct interest to the user.
Instance Method Summary collapse
-
#initialize(width = 0, fmtstr = nil) ⇒ Report
constructor
Returns an initialized Report instance.
-
#item(label = "", *fmt, &blk) ⇒ Object
(also: #report)
Prints the label and measured time for the block, formatted by fmt.
Constructor Details
#initialize(width = 0, fmtstr = nil) ⇒ Report
Returns an initialized Report instance. Usually, one doesn’t call this method directly, as new Report objects are created by the #benchmark and #bm methods. width and fmtstr are the label offset and format string used by Tms#format.
373 374 375 |
# File 'lib/benchmark.rb', line 373 def initialize(width = 0, fmtstr = nil) @width, @fmtstr = width, fmtstr end |
Instance Method Details
#item(label = "", *fmt, &blk) ⇒ Object Also known as: report
Prints the label and measured time for the block, formatted by fmt. See Tms#format for the formatting rules.
382 383 384 385 386 387 |
# File 'lib/benchmark.rb', line 382 def item(label = "", *fmt, &blk) # :yield: OUTPUT.print label.ljust(@width) res = Benchmark::measure(&blk) OUTPUT.print res.format(@fmtstr, *fmt) res end |