Class: BenchmarkDriver::Output
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output
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: All, Compare, Markdown, Record, Simple
Class Method Summary
collapse
Instance Method Summary
collapse
-
#initialize(type:, metrics:, jobs:, contexts:, options:) ⇒ Output
constructor
BenchmarkDriver::Output is pluggable.
-
#metrics=(metrics) ⇒ Object
-
#report(values:, all_values: nil, duration: nil, loop_count: nil, environment: {}) ⇒ Object
-
#with_benchmark(&block) ⇒ Object
-
#with_context(name:, executable:, gems: {}, prelude: '', &block) ⇒ Object
-
#with_job(name:, &block) ⇒ Object
-
#with_warmup(&block) ⇒ Object
Constructor Details
#initialize(type:, metrics:, jobs:, contexts:, options:) ⇒ Output
BenchmarkDriver::Output is pluggable. Create ‘BenchmarkDriver::Output::Foo` as benchmark_dirver-output-foo.gem and specify `-o foo`.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/benchmark_driver/output.rb', line 42
def initialize(type:, metrics:, jobs:, contexts:, options:)
output = ::BenchmarkDriver::Output.get(type)
output_params = output.instance_method(:initialize).parameters.select do |type, _name|
type == :keyreq || type == :key
end.map(&:last)
kwargs = {}
if output_params.include?(:options)
kwargs[:options] = options
end
@output = output.new(
metrics: metrics,
jobs: jobs,
contexts: contexts,
**kwargs,
)
end
|
Class Method Details
.get(type) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/benchmark_driver/output.rb', line 24
def self.get(type)
if type.include?(':')
raise ArgumentError.new("Output type '#{type}' cannot contain ':'")
end
require "benchmark_driver/output/#{type}" camelized = type.split('_').map(&:capitalize).join
::BenchmarkDriver::Output.const_get(camelized, false)
end
|
Instance Method Details
#metrics=(metrics) ⇒ Object
63
64
65
|
# File 'lib/benchmark_driver/output.rb', line 63
def metrics=(metrics)
@output.metrics = metrics
end
|
#report(values:, all_values: nil, duration: nil, loop_count: nil, environment: {}) ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/benchmark_driver/output.rb', line 96
def report(values:, all_values: nil, duration: nil, loop_count: nil, environment: {})
result = BenchmarkDriver::Result.new(
values: values,
all_values: all_values,
duration: duration,
loop_count: loop_count,
environment: environment,
)
@output.report(result)
end
|
#with_benchmark(&block) ⇒ Object
71
72
73
|
# File 'lib/benchmark_driver/output.rb', line 71
def with_benchmark(&block)
@output.with_benchmark(&block)
end
|
#with_context(name:, executable:, gems: {}, prelude: '', &block) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/benchmark_driver/output.rb', line 86
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
76
77
78
79
80
81
|
# File 'lib/benchmark_driver/output.rb', line 76
def with_job(name:, &block)
job = BenchmarkDriver::Job.new(name: name)
@output.with_job(job) do
block.call
end
end
|
#with_warmup(&block) ⇒ Object
67
68
69
|
# File 'lib/benchmark_driver/output.rb', line 67
def with_warmup(&block)
@output.with_warmup(&block)
end
|