Skip to content

Instantly share code, notes, and snippets.

@kudosqujo
Created November 30, 2020 01:41
[Ruby Benchmark]
# Copy this into an irb session for easy benchmark testing
require 'benchmark'
# @param labels_and_procs [Hash{String=>Proc}]
def bm_test(labels_and_procs, n = 1000, label_width = 7)
puts "running #{n} times"
::Benchmark.bm(label_width) do |x|
labels_and_procs.each do |label, proc|
x.report("#{label}:") { n.times { proc.call } }
end
end
end
def bmbm_test(labels_and_procs, n = 1000, label_width = 7)
puts "running #{n} times"
::Benchmark.bmbm(label_width) do |x|
labels_and_procs.each do |label, proc|
x.report("#{label}:") { n.times { proc.call } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment