class BenchmarkInterface::BenchmarkSet

Attributes

iterations[R]

Public Class Methods

current() click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 80
def self.current
  @@current
end
new() click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 14
def initialize
  @benchmarks = []
  @counter = 0
  @@current = self
  @iterations = 1
end

Public Instance Methods

benchmark(name) click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 74
def benchmark(name)
  benchmarks([name]).first
end
benchmarks(names=nil) click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 66
def benchmarks(names=nil)
  if names
    @benchmarks.select { |b| names.include?(b.name) }
  else
    @benchmarks
  end
end
implicit_name() click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 38
def implicit_name
  file = File.basename(@path, '.rb')
  @counter += 1
  "#{file}:#{@counter}"
end
load_benchmarks(path) click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 21
def load_benchmarks(path)
  @path = path
  @@current = self
  load(path)
end
load_mri_benchmarks(path, options) click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 27
def load_mri_benchmarks(path, options)
  @path = path
  @@current = self
  Frontends::MRI.load_mri path, options
end
prepare() click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 44
def prepare
  # Don't give benchmarks line numbers if there's only one

  if @benchmarks.size == 1
    @benchmarks.first.remove_line_numbers
  end

  # Give benchmarks iterations if needed

  if @benchmarks.any?(&:needs_iterating?)
    iterations = @benchmarks.map(&:iterations_for_one_second).min

    puts "This benchmark set contains blocks that want a number of iterations - running all iterations #{iterations} times"

    @benchmarks.each do |b|
      b.iterate iterations
    end

    @iterations = iterations
  end
end
register(name, code) click to toggle source
# File lib/benchmark-interface/benchmark-set.rb, line 33
def register(name, code)
  name = implicit_name unless name
  @benchmarks.push Benchmark.new(name, code)
end