Sha256: 34800bc6e558b6d1b36074074379cd3f37763e39346c2980e5ef9889e23c7937

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

class BenchmarkDriver::Output::Record
  # @param [BenchmarkDriver::Metrics::Type] metrics_type
  attr_writer :metrics_type

  # @param [Array<BenchmarkDriver::*::Job>] jobs
  # @param [Array<BenchmarkDriver::Config::Executable>] executables
  def initialize(jobs:, executables:)
    @jobs = jobs
    @executables = executables
    @metrics_by_job = Hash.new do |h1, k1|
      h1[k1] = Hash.new { |h2, k2| h2[k2] = [] }
    end
  end

  def with_warmup(&block)
    $stdout.print 'warming up'
    block.call
  ensure
    $stdout.puts
  end

  def with_benchmark(&block)
    @with_benchmark = true
    $stdout.print 'benchmarking'
    block.call
  ensure
    $stdout.puts
    @with_benchmark = false
    save_record
  end

  # @param [BenchmarkDriver::*::Job] job
  def with_job(job, &block)
    @current_job = job
    block.call
  end

  # @param [BenchmarkDriver::Metrics] metrics
  def report(metrics)
    $stdout.print '.'
    if @with_benchmark
      @metrics_by_job[@current_job][:benchmark] << metrics
    else
      @metrics_by_job[@current_job][:warmup] << metrics
    end
  end

  private

  def save_record
    jobs = @benchmark_metrics
    yaml = {
      'type' => 'recorded',
      'metrics_by_job' => @metrics_by_job,
      'metrics_type' => @metrics_type,
    }.to_yaml
    File.write('benchmark_driver.record.yml', yaml)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
benchmark_driver-0.10.16 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.15 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.14 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.13 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.12 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.11 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.10 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.9 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.8 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.7 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.6 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.5 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.4 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.3 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.2 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.1 lib/benchmark_driver/output/record.rb
benchmark_driver-0.10.0 lib/benchmark_driver/output/record.rb