Skip to content

Instantly share code, notes, and snippets.

@gbrl
Forked from davidvandusen/benchmark_with_block.rb
Last active April 28, 2016 17:54
Show Gist options
  • Save gbrl/2aab5be6c290a0a15936a74a3a9e0b3f to your computer and use it in GitHub Desktop.
Save gbrl/2aab5be6c290a0a15936a74a3a9e0b3f to your computer and use it in GitHub Desktop.
def benchmark
start = Time.now
yield
running_time = Time.now - start
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
long_string = "apple"*100000000
running_time = benchmark { long_string.reverse }
puts "string.reverse took #{running_time} seconds to run"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment