Created
February 27, 2019 15:23
-
-
Save vasilakisfil/4f510d8ca2da17dce4f71bdf547d5118 to your computer and use it in GitHub Desktop.
simple timing/benchmark mechanism for Ruby
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
class TimingBenchmark | |
def measure(label, &block) | |
@label_times ||= {} | |
start = Time.now | |
result = block.call | |
@label_times[label] = Time.now - start | |
return result | |
end | |
def printout_times | |
@label_times.each do |label, value| | |
puts "#{label}: #{value}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment