Skip to content

Instantly share code, notes, and snippets.

@madeleine68
Forked from davidvandusen/benchmark_with_block.rb
Last active November 6, 2021 00:30
Show Gist options
  • Save madeleine68/2f70666ad586d8f4b81418aaf745d55b to your computer and use it in GitHub Desktop.
Save madeleine68/2f70666ad586d8f4b81418aaf745d55b to your computer and use it in GitHub Desktop.
def benchmark
start_time = Time.now
yield
end_time = Time.now
x = end_time - start_time
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