Sha256: 7264f1912d2ddc879d1444d1484ee69e2d30b56ebe68df7a90b89d5acd0c4c4d

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'kalibera'
require 'benchmark/ips'

# Enable and start GC before each job run. Disable GC afterwards.
#
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182
class GCSuite
  def warming(*)
    run_gc
  end

  def running(*)
    run_gc
  end

  def warmup_stats(*)
  end

  def add_report(*)
  end

private

  def run_gc
    GC.enable
    GC.start
    GC.disable
  end
end

def as_boolean(val, default: nil)
  case val.to_s.strip.downcase
  when "true", "t", "yes", "y", "on", "1"
    true
  when "false", "f", "no", "n", "off", "0"
    false
  else
    raise "Unknown boolean value #{val}" if default.nil?

    default
  end
end

def section(title = nil)
  puts "\n#### #{title}" if title
  puts "\n```"
  GC.start
  Benchmark.ips do |bench|
    bench.config suite: GCSuite.new if GC_DISABLED
    bench.config stats: :bootstrap, confidence: 95

    yield bench
    bench.compare!
  end
  puts "```"
end

def display_benchmark_header
  puts
  puts "### Environment"
  puts
  puts RUBY_DESCRIPTION
  puts "GC Disabled: #{GC_DISABLED}"
  puts
  puts "### Test Cases"
end

GC_DISABLED = as_boolean(ENV['GC_DISABLED'], default: false)

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
radius-spec-0.11.0 benchmarks/bm_setup.rb
radius-spec-0.10.0 benchmarks/bm_setup.rb
radius-spec-0.9.0 benchmarks/bm_setup.rb
radius-spec-0.8.0 benchmarks/bm_setup.rb
radius-spec-0.7.0 benchmarks/bm_setup.rb
radius-spec-0.6.0 benchmarks/bm_setup.rb
radius-spec-0.5.0 benchmarks/bm_setup.rb