Sha256: b2ee9beb573408198b2ea25e83e93a0503d827b6d2f204d1165f267372798e1f

Contents?: true

Size: 1.36 KB

Versions: 39

Compression:

Stored size: 1.36 KB

Contents

class BenchmarkDriver::Output::Record
  # @param [Array<BenchmarkDriver::Metric>] metrics
  # @param [Array<BenchmarkDriver::Job>] jobs
  # @param [Array<BenchmarkDriver::Context>] contexts
  def initialize(metrics:, jobs:, contexts:)
    @metrics = metrics
    @job_warmup_context_result = Hash.new do |h1, job|
      h1[job] = Hash.new do |h2, warmup|
        h2[warmup] = Hash.new do |h3, context|
          h3[context] = {}
        end
      end
    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)
    @job = job
    block.call
  end

  # @param [BenchmarkDriver::Context] context
  def with_context(context, &block)
    @context = context
    block.call
  end

  # @param [BenchmarkDriver::Result] result
  def report(result)
    $stdout.print '.'
    @job_warmup_context_result[@job][!@with_benchmark][@context] = result
  end

  private

  def save_record
    yaml = {
      'type' => 'recorded',
      'job_warmup_context_result' => @job_warmup_context_result,
      'metrics' => @metrics,
    }.to_yaml
    File.write('benchmark_driver.record.yml', yaml)
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
benchmark_driver-0.16.5 lib/benchmark_driver/output/record.rb
benchmark_driver-0.16.4 lib/benchmark_driver/output/record.rb
benchmark_driver-0.16.3 lib/benchmark_driver/output/record.rb
benchmark_driver-0.16.2 lib/benchmark_driver/output/record.rb
benchmark_driver-0.16.1 lib/benchmark_driver/output/record.rb
benchmark_driver-0.16.0 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.18 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.17 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.16 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.15 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.14 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.13 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.12 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.11 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.10 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.9 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.8 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.7 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.6 lib/benchmark_driver/output/record.rb
benchmark_driver-0.15.5 lib/benchmark_driver/output/record.rb