Module: Benchmark::Driver

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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'0.8.2'

Class Method Summary collapse

Class Method Details

.run(config) ⇒ Object

Main function which is used by both RubyDriver and YamlDriver.



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
# File 'lib/benchmark/driver.rb', line 16

def run(config)
  validate_config(config)
  if config.runner_options.type.nil?
    config.runner_options.type = runner_type_for(config)
  end

  if config.runner_options.bundler
    config.runner_options.executables.each do |executable|
      Benchmark::Driver::BundleInstaller.bundle_install_for(executable)
      executable.command << '-rbundler/setup'
    end
  end

  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