Class: Benchmark::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/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

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.



369
370
371
# File 'lib/benchmark.rb', line 369

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.



378
379
380
381
382
383
# File 'lib/benchmark.rb', line 378

def item(label = "", *fmt, &blk) # :yield:
  print label.ljust(@width)
  res = Benchmark::measure(&blk)
  print res.format(@fmtstr, *fmt)
  res
end