a small ruby method to benchmark a block of code
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
def benchmark(count = 1, &block) | |
start = Time.now | |
count.times do |i| | |
yield | |
end | |
duration = Time.now - start | |
per_sec = count / duration | |
return benchmark(count*2, &block) if duration < 0.5 | |
return per_sec.to_f | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment