Class: Benchkit::BenchmarkRoot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, prelude: '', loop_count: nil, benchmark: nil, benchmarks: []) ⇒ BenchmarkRoot

Returns a new instance of BenchmarkRoot.

Parameters:

  • name (String)
  • prelude (String) (defaults to: '')
  • loop_count (Integer, nil) (defaults to: nil)
  • benchmark (String, nil) (defaults to: nil)
    • For running single instant benchmark

  • benchmarks (Array<Hash>) (defaults to: [])
    • For running multiple benchmarks



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/benchkit.rb', line 96

def initialize(name:, prelude: '', loop_count: nil, benchmark: nil, benchmarks: [])
  if benchmark
    unless benchmarks.empty?
      raise ArgumentError.new("Only either :benchmark or :benchmarks can be specified")
    end
    @benchmarks = [BenchmarkScript.new(name: name, prelude: prelude, benchmark: benchmark)]
  else
    @benchmarks = benchmarks.map do |hash|
      BenchmarkScript.new(Hash[hash.map { |k, v| [k.to_sym, v] }]).tap do |b|
        b.inherit_root(prelude: prelude, loop_count: loop_count)
      end
    end
  end
end

Instance Attribute Details

#benchmarksArray<BenchmarkScript> (readonly)

Returns:



112
113
114
# File 'lib/benchkit.rb', line 112

def benchmarks
  @benchmarks
end