Class: BenchmarkDriver::Runner::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/runner/memory.rb

Overview

Max resident set size

Constant Summary collapse

METRIC =
BenchmarkDriver::Metric.new(
  name: 'Max resident set size', unit: 'bytes', larger_better: false, worse_word: 'larger',
)
Job =

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

Class.new(BenchmarkDriver::DefaultJob)
JobParser =

Dynamically fetched and used by BenchmarkDriver::JobParser.parse

BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC])

Instance Method Summary collapse

Constructor Details

#initialize(config:, output:, contexts:) ⇒ Memory



22
23
24
25
26
# File 'lib/benchmark_driver/runner/memory.rb', line 22

def initialize(config:, output:, contexts:)
  @config = config
  @output = output
  @contexts = contexts
end

Instance Method Details

#run(jobs) ⇒ Object

This method is dynamically called by BenchmarkDriver::JobRunner.run



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
55
56
57
58
59
60
61
# File 'lib/benchmark_driver/runner/memory.rb', line 30

def run(jobs)
  # Currently Linux's time(1) support only...
  case Etc.uname.fetch(:sysname)
  when 'Linux'
    @time_command = ['/usr/bin/time']
  when 'Darwin'
    @time_command = ['/usr/bin/time', '-l']
  else
    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|
          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 => result.value }, all_values: { METRIC => result.all_values }, loop_count: job.loop_count)
          end
        end
      end
    end
  end
end