Sha256: 6ad052ed4495381715e5b83582e25daf54a4d314025e45be682461008da9646e

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module BenchmarkDriver
  module Runner
    require 'benchmark_driver/runner/ips'
    require 'benchmark_driver/runner/memory'
    require 'benchmark_driver/runner/time'
  end

  class << Runner
    # Main function which is used by both CLI and `Benchmark.driver`.
    # @param [Array<BenchmarkDriver::*::Job>] jobs
    # @param [BenchmarkDriver::Config] config
    def run(jobs, config:)
      runner_config = Config::RunnerConfig.new(
        executables: config.executables,
        repeat_count: config.repeat_count,
        run_duration: config.run_duration,
      )

      jobs.group_by(&:class).each do |klass, jobs_group|
        runner = runner_for(klass)
        output = Output.find(config.output_type).new(
          jobs: jobs,
          executables: config.executables,
          metrics_type: runner::MetricsType,
        )
        runner.new(config: runner_config, output: output).run(jobs)
      end
    end

    private

    # Dynamically find class (BenchmarkDriver::*::JobRunner) for plugin support
    # @param [Class] klass - BenchmarkDriver::*::Job
    # @return [Class]
    def runner_for(klass)
      unless match = klass.name.match(/\ABenchmarkDriver::Runner::(?<namespace>[^:]+)::Job\z/)
        raise "Unexpected job class: #{klass}"
      end
      BenchmarkDriver.const_get("Runner::#{match[:namespace]}", false)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
benchmark_driver-0.9.0 lib/benchmark_driver/runner.rb