Module: BenchmarkInterface::Backends::Bench9000

Defined in:
lib/benchmark-interface/backends/bench9000.rb

Constant Summary collapse

MIN_SAMPLING_TIME =

seconds

0.1

Class Method Summary collapse

Class Method Details

.loading_real?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/benchmark-interface/backends/bench9000.rb', line 81

def self.loading_real?
  @loading_real
end

.run(benchmark_set, names, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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