Class: BenchmarkDriver::Output

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

Overview

BenchmarkDriver::Runner::* –> BenchmarkDriver::Output –> BenchmarkDriver::Output::*

This is interface between runner plugin and output plugin, so that they can be loosely coupled and to simplify implementation of both runner and output.

Runner should call its interface in the following manner:

metrics=
with_warmup
  with_job(name:)
    with_context(name:, executable:, gems:)
      report(values:, duration: nil, loop_count: nil, environment: {})
with_benchmark
  with_job(name:)
    with_context(name:, executable:, gems:)
      report(values:, duration: nil, loop_count: nil, environment: {})

Defined Under Namespace

Classes: Compare, Markdown, Record, Simple

Instance Method Summary collapse

Constructor Details

#initialize(type:, metrics:, jobs:, contexts:) ⇒ Output

BenchmarkDriver::Output is pluggable. Create ‘BenchmarkDriver::Output::Foo` as benchmark_dirver-output-foo.gem and specify `-o foo`.

Parameters:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/benchmark_driver/output.rb', line 30

def initialize(type:, metrics:, jobs:, contexts:)
  if type.include?(':')
    raise ArgumentError.new("Output type '#{type}' cannot contain ':'")
  end

  require "benchmark_driver/output/#{type}" # for plugin
  camelized = type.split('_').map(&:capitalize).join

  @output = ::BenchmarkDriver::Output.const_get(camelized, false).new(
    metrics: metrics,
    jobs: jobs,
    contexts: contexts,
  )
end

Instance Method Details

#metrics=(metrics) ⇒ Object

Parameters:



46
47
48
# File 'lib/benchmark_driver/output.rb', line 46

def metrics=(metrics)
  @output.metrics = metrics
end

#report(values:, duration: nil, loop_count: nil, environment: {}) ⇒ Object

Parameters:



78
79
80
81
82
83
84
85
86
# File 'lib/benchmark_driver/output.rb', line 78

def report(values:, duration: nil, loop_count: nil, environment: {})
  result = BenchmarkDriver::Result.new(
    values: values,
    duration: duration,
    loop_count: loop_count,
    environment: environment,
  )
  @output.report(result)
end

#with_benchmark(&block) ⇒ Object



54
55
56
# File 'lib/benchmark_driver/output.rb', line 54

def with_benchmark(&block)
  @output.with_benchmark(&block)
end

#with_context(name:, executable:, gems: {}, prelude: '', &block) ⇒ Object

Parameters:

  • name (String)
  • executable (BenchmarkDriver::Config::Executable)
  • gems (Hash{ String => String}) (defaults to: {})


69
70
71
72
73
74
# File 'lib/benchmark_driver/output.rb', line 69

def with_context(name:, executable:, gems: {}, prelude: '', &block)
  context = BenchmarkDriver::Context.new(name: name, executable: executable, gems: gems, prelude: prelude)
  @output.with_context(context) do
    block.call
  end
end

#with_job(name:, &block) ⇒ Object

Parameters:

  • name (String)


59
60
61
62
63
64
# File 'lib/benchmark_driver/output.rb', line 59

def with_job(name:, &block)
  job = BenchmarkDriver::Job.new(name: name)
  @output.with_job(job) do
    block.call
  end
end

#with_warmup(&block) ⇒ Object



50
51
52
# File 'lib/benchmark_driver/output.rb', line 50

def with_warmup(&block)
  @output.with_warmup(&block)
end