module Benchmark::Runner

Public Class Methods

compute_ips(time, warmup, label) { || ... } click to toggle source
# File lib/rubybench_runner/support/benchmark_runner.rb, line 19
def self.compute_ips(time, warmup, label, &block)
  report = Benchmark.ips(time, warmup, true) do |x|
    x.report(label) { yield }
  end

  report.entries.first
end
compute_objects() { || ... } click to toggle source
# File lib/rubybench_runner/support/benchmark_runner.rb, line 27
def self.compute_objects(&block)
  if block_given?
    key =
      if RUBY_VERSION < '2.2'
        :total_allocated_object
      else
        :total_allocated_objects
      end

    before = GC.stat[key]
    yield
    after = GC.stat[key]
    after - before
  end
end
print_output(ips_result, objects_result, label, version) click to toggle source
run(label=nil, version:, time:, disable_gc:, warmup:, &block) click to toggle source
# File lib/rubybench_runner/support/benchmark_runner.rb, line 6
def self.run(label=nil, version:, time:, disable_gc:, warmup:, &block)
  unless block_given?
    raise ArgumentError.new, "You must pass block to run"
  end

  GC.disable if disable_gc

  ips_result = compute_ips(time, warmup, label, &block)
  objects_result = compute_objects(&block)

  print_output(ips_result, objects_result, label, version)
end