Class: RBM::Benchmarker

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :times => 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fragments, options) ⇒ Benchmarker

Returns a new instance of Benchmarker.



11
12
13
14
15
16
# File 'lib/rbm/benchmarker.rb', line 11

def initialize(fragments, options)
  @options = DEFAULT_OPTIONS.merge(options)

  compile_prerun(options[:prerun])
  @fragments = fragments.map { |name, fragment| [name, compile_fragment(fragment, options[:prerun], name)] }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/rbm/benchmarker.rb', line 9

def options
  @options
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rbm/benchmarker.rb', line 18

def run
  width = @fragments.map { |name, method| name.size }.max
  Benchmark.bm(width) do |bm|
    @fragments.each do |name, method|
      bm.report(name) do
        # TODO: wrap errors from fragment execution
        options[:times].times { send(method) }
      end
    end
  end
end