Skip to content

Instantly share code, notes, and snippets.

@reednj
Last active March 11, 2016 05:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save reednj/501606828ba041bc7442 to your computer and use it in GitHub Desktop.
a small ruby method to benchmark a block of code
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