class BenchmarkDriver::Runner::Rsskb

Max resident set size

Constants

BenchmarkScript

@param [String] prelude @param [String] script @param [String] teardown @param [Integer] loop_count

Job

JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches “*::Job”

JobParser

Dynamically fetched and used by `BenchmarkDriver::JobParser.parse`

METRIC

Using the RubyBench's original label

Public Class Methods

new(config:, output:, contexts:) click to toggle source

@param [BenchmarkDriver::Config::RunnerConfig] config @param [BenchmarkDriver::Output] output @param [BenchmarkDriver::Context] contexts

# File lib/benchmark_driver/runner/rsskb.rb, line 23
def initialize(config:, output:, contexts:)
  @config = config
  @output = output
  @contexts = contexts
end

Public Instance Methods

run(jobs) click to toggle source

This method is dynamically called by `BenchmarkDriver::JobRunner.run` @param [Array<BenchmarkDriver::Default::Job>] jobs

# File lib/benchmark_driver/runner/rsskb.rb, line 31
def run(jobs)
  # Currently Linux's time(1) support only...
  if Etc.uname.fetch(:sysname) != 'Linux'
    raise "memory output is not supported for '#{Etc.uname[:sysname]}' for now"
  end

  if jobs.any? { |job| job.loop_count.nil? }
    jobs = jobs.map do |job|
      job.loop_count ? job : Job.new(job.to_h.merge(loop_count: 1))
    end
  end

  @output.with_benchmark do
    jobs.each do |job|
      @output.with_job(name: job.name) do
        job.runnable_contexts(@contexts).each do |context|
          repeat_result = BenchmarkDriver::Repeater.with_repeat(config: @config, larger_better: false) do
            run_benchmark(job, context: context)
          end
          @output.with_context(name: context.name, executable: context.executable, gems: context.gems, prelude: context.prelude) do
            @output.report(values: { METRIC => repeat_result.value }, loop_count: job.loop_count)
          end
        end
      end
    end
  end
end

Private Instance Methods

run_benchmark(job, context:) click to toggle source

@param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil @param [BenchmarkDriver::Context] context @return [BenchmarkDriver::Metrics]

# File lib/benchmark_driver/runner/rsskb.rb, line 64
def run_benchmark(job, context:)
  benchmark = BenchmarkScript.new(
    preludes:   [context.prelude, job.prelude],
    script:     job.script,
    teardown:   job.teardown,
    loop_count: job.loop_count,
  )

  with_script(benchmark.render) do |path|
    Tempfile.open(['rsskb-', '.txt']) do |f|
      stdout = IO.popen(['/usr/bin/time', *context.executable.command, path], err: f.path, &:read)
      stderr = File.read(f.path)
      if $?.success?
        match_data = /^(?<user>\d+.\d+)user\s+(?<system>\d+.\d+)system\s+(?<elapsed1>\d+):(?<elapsed2>\d+.\d+)elapsed.+\([^\s]+\s+(?<maxresident>\d+)maxresident\)k$/.match(stderr)
        raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident]

        Integer(match_data[:maxresident])
      else
        $stdout.print(stdout)
        $stderr.print(stderr)
        BenchmarkDriver::Result::ERROR
      end
    end
  end
end
with_script(script) { |path| ... } click to toggle source
# File lib/benchmark_driver/runner/rsskb.rb, line 90
def with_script(script)
  if @config.verbose >= 2
    sep = '-' * 30
    $stdout.puts "\n\n#{sep}[Script begin]#{sep}\n#{script}#{sep}[Script end]#{sep}\n\n"
  end

  Tempfile.open(['benchmark_driver-', '.rb']) do |f|
    f.puts script
    f.close
    return yield(f.path)
  end
end