Module: Benchmark::Driver

Defined in:
lib/benchmark/driver.rb,
lib/benchmark/driver/error.rb,
lib/benchmark/driver/version.rb

Defined Under Namespace

Modules: Time, YamlParser Classes: BenchmarkResult, Configuration, DurationRunner, Error, ExecutionTimeTooShort, RepeatableRunner, RubyDslParser

Constant Summary collapse

VERSION =
'0.4.2'

Class Method Summary collapse

Class Method Details

.run(config) ⇒ Object

Main function which is used by both RubyDriver and YamlDriver.

Parameters:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/benchmark/driver.rb', line 6

def run(config)
  validate_config(config)

  runner_class = Runner.find(config.runner_options.type)
  output_class = Output.find(config.output_options.type)

  missing_fields = output_class::REQUIRED_FIELDS - runner_class::SUPPORTED_FIELDS
  unless missing_fields.empty?
    raise ArgumentError.new(
      "#{output_class.name} requires #{missing_fields.inspect} fields "\
      "which are not supported by #{runner_class.name}. Try using another runner."
    )
  end

  without_stdout_buffering do
    runner = runner_class.new(
      config.runner_options,
      output: output_class.new(
        jobs:        config.jobs,
        executables: config.runner_options.executables,
        options:     config.output_options,
      ),
    )
    runner.run(config)
  end
rescue Benchmark::Driver::Error => e
  $stderr.puts "\n\nFailed to execute benchmark!\n\n#{e.class.name}:\n  #{e.message}"
  exit 1
end