Created
November 30, 2020 01:41
[Ruby Benchmark]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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