Class: BenchmarkDriver::Runner::Ips

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/runner/ips.rb

Overview

Show iteration per second.

Direct Known Subclasses

Block, Time

Constant Summary collapse

METRIC =
BenchmarkDriver::Metric.new(name: 'Iteration per second', unit: 'i/s')
Job =

JobParser returns this, ‘BenchmarkDriver::Runner.runner_for` searches “*::Job”

Class.new(BenchmarkDriver::DefaultJob)
JobParser =

Dynamically fetched and used by ‘BenchmarkDriver::JobParser.parse`

BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC])

Instance Method Summary collapse

Constructor Details

#initialize(config:, output:, contexts:) ⇒ Ips

Returns a new instance of Ips.

Parameters:



20
21
22
23
24
# File 'lib/benchmark_driver/runner/ips.rb', line 20

def initialize(config:, output:, contexts:)
  @config = config
  @output = output
  @contexts = contexts
end

Instance Method Details

#run(jobs) ⇒ Object

This method is dynamically called by ‘BenchmarkDriver::JobRunner.run`

Parameters:

  • jobs (Array<BenchmarkDriver::Default::Job>)


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
# File 'lib/benchmark_driver/runner/ips.rb', line 28

def run(jobs)
  if jobs.any? { |job| job.loop_count.nil? }
    @output.with_warmup do
      jobs = jobs.map do |job|
        next job if job.loop_count # skip warmup if loop_count is set

        @output.with_job(name: job.name) do
          context = job.runnable_contexts(@contexts).first
          duration, loop_count = run_warmup(job, context: context)
          value, duration = value_duration(duration: duration, loop_count: loop_count)

          @output.with_context(name: context.name, executable: context.executable, gems: context.gems, prelude: context.prelude) do
            @output.report(values: { metric => value }, duration: duration, loop_count: loop_count)
          end

          loop_count = (loop_count.to_f * @config.run_duration / duration).floor
          Job.new(**job.to_h.merge(loop_count: loop_count))
        end
      end
    end
  end

  @output.with_benchmark do
    jobs.each do |job|
      @output.with_job(name: job.name) do
        job.runnable_contexts(@contexts).each do |context|
          repeat_params = { config: @config, larger_better: true, rest_on_average: :average }
          result = BenchmarkDriver::Repeater.with_repeat(**repeat_params) do
            run_benchmark(job, context: context)
          end
          value, duration = result.value
          @output.with_context(name: context.name, executable: context.executable, gems: context.gems, prelude: context.prelude) do
            @output.report(
              values: { metric => value },
              all_values: { metric => result.all_values },
              duration: duration,
              loop_count: job.loop_count,
            )
          end
        end
      end
    end
  end
end