Skip to content

Instantly share code, notes, and snippets.

@charmainetham
Created April 30, 2016 20:22
Show Gist options
  • Save charmainetham/4e6f187ca6b09f63728e57ba89be9fce to your computer and use it in GitHub Desktop.
Save charmainetham/4e6f187ca6b09f63728e57ba89be9fce to your computer and use it in GitHub Desktop.
benchmark with blocks
def benchmark
starting_time = Time.now
yield
end_time = Time.now
end_time - starting_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