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.



374
375
376
# File 'lib/benchmark.rb', line 374

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.



383
384
385
386
387
388
# File 'lib/benchmark.rb', line 383

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