Created
August 6, 2016 15:42
-
-
Save pca2/ac647a7e6577d99c9a7b3fe2ba0edb9b to your computer and use it in GitHub Desktop.
Ruby Benchmarking Template
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
require 'benchmark' | |
#at its most basic, it looks like this: | |
Benchmark.bm do |bm| | |
bm.report {some code} | |
bm.report {some other code} | |
end | |
#A more robust example | |
iterations = 5 | |
puts "Iterations: #{iterations.to_s}" | |
Benchmark.bmbm do |bm| | |
#bmbm forces a rehersal and GC, to test on a 'warm' | |
bm.report('label1') do | |
iterations.times do | |
#run some code | |
end | |
end | |
bm.report('label2') do | |
iterations.times do | |
#run some code | |
end | |
end | |
end | |
=begin you can also pass an int to as an argument to the Benchmark.bm method. | |
This signifies how much padding the header labels should have in the result output. | |
If you pass labels to report, but dont set this value high enough, your output wont line up properly. | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment