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