123456789_123456789_123456789_123456789_123456789_

Class: Benchmark::Job

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/benchmark.rb

Overview

A Job is a sequence of labelled blocks to be processed by the bmbm method. It is of little direct interest to the user.

Class Method Summary

Instance Attribute Summary

  • #list readonly

    An array of 2-element arrays, consisting of label and block pairs.

  • #width readonly

    Length of the widest label in the #list.

Instance Method Summary

Constructor Details

.new(width) ⇒ Job

Returns an initialized Job instance. Usually, one doesn’t call this method directly, as new Job objects are created by the Benchmark#bmbm method. #width is a initial value for the label offset used in formatting; the Benchmark#bmbm method passes its #width argument to this constructor.

[ GitHub ]

  
# File 'lib/benchmark.rb', line 326

def initialize(width)
  @width = width
  @list = []
end

Instance Attribute Details

#list (readonly)

An array of 2-element arrays, consisting of label and block pairs.

[ GitHub ]

  
# File 'lib/benchmark.rb', line 346

attr_reader :list

#width (readonly)

Length of the widest label in the #list.

[ GitHub ]

  
# File 'lib/benchmark.rb', line 349

attr_reader :width

Instance Method Details

#item(label = "", &blk) Also known as: #report

Registers the given label and block pair in the job list.

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/benchmark.rb', line 334

def item(label = "", &blk) # :yield:
  raise ArgumentError, "no block" unless block_given?
  label = label.to_s
  w = label.length
  @width = w if @width < w
  @list << [label, blk]
  self
end

#report(label = "", &blk)

Alias for #item.

[ GitHub ]

  
# File 'lib/benchmark.rb', line 343

alias report item