Skip to content

Instantly share code, notes, and snippets.

@vasilakisfil
Created February 27, 2019 15:23
Show Gist options
  • Save vasilakisfil/4f510d8ca2da17dce4f71bdf547d5118 to your computer and use it in GitHub Desktop.
Save vasilakisfil/4f510d8ca2da17dce4f71bdf547d5118 to your computer and use it in GitHub Desktop.
simple timing/benchmark mechanism for Ruby
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