Skip to content

Instantly share code, notes, and snippets.

@stupeters187
Created March 31, 2016 15:59
Show Gist options
  • Save stupeters187/c10c9efbc676b7cd6c12ea2f92695dce to your computer and use it in GitHub Desktop.
Save stupeters187/c10c9efbc676b7cd6c12ea2f92695dce to your computer and use it in GitHub Desktop.
def benchmark
start_time = Time.now
yield()
end_time = Time.now
end_time - start_time
# Your benchmarking code goes here.
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