module BenchmarkInterface::Backends::Bench9000

Constants

MIN_SAMPLING_TIME

Public Class Methods

loading_real?() click to toggle source
# File lib/benchmark-interface/backends/bench9000.rb, line 81
def self.loading_real?
  @loading_real
end
run(benchmark_set, names, options) click to toggle source
# File lib/benchmark-interface/backends/bench9000.rb, line 15
def self.run(benchmark_set, names, options)
  unless names.size == 1
    abort 'The bench9000 backend only works when you run just one benchmark at a time - specify the name on the command line'
  end

  unless options['--no-scale']
    min_time = benchmark_set.benchmarks.map(&:basic_iteration_time).min

    if min_time < MIN_SAMPLING_TIME
      short_iterations = true
      samples = (MIN_SAMPLING_TIME / min_time / MIN_SAMPLING_TIME).to_i
      puts "These are short benchmarks - we're running each #{samples} times so they take about a second and using the micro harness"
    end
  end

  benchmark = benchmark_set.benchmark(names.first)
  block = benchmark.block

  Object.instance_eval do
    if short_iterations
      define_method(:micro_harness_input) do
        nil
      end

      define_method(:micro_harness_iterations) do
        samples
      end

      define_method(:micro_harness_sample) do |input|
        block.call
      end

      define_method(:micro_harness_expected) do
        raise 'not expecting this to be called, as we\'ve patched harness_verify'
      end
    else
      define_method(:harness_input) do
        nil
      end

      define_method(:harness_sample) do |input|
        block.call
      end

      define_method(:harness_verify) do |output|
        true
      end
    end

  end
  
  @loading_real = true

  if short_iterations
    benchmark_interface_original_require 'bench9000/micro-harness'

    Object.instance_eval do
      define_method(:harness_verify) do |output|
        true
      end
    end
  end

  benchmark_interface_original_require 'bench9000/harness'
end