Created
November 30, 2020 01:41
-
-
Save kudosqujo/721175e0e0f39d18a1e5e573197d3b46 to your computer and use it in GitHub Desktop.
[Ruby Benchmark]
This file contains hidden or 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