Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created July 2, 2015 06:21
Show Gist options
  • Save tim-br/fa0682463f9376659e6a to your computer and use it in GitHub Desktop.
Save tim-br/fa0682463f9376659e6a to your computer and use it in GitHub Desktop.
def benchmark
# Your benchmarking code goes here.
beginning_time = Time.now
foo = yield
end_time = Time.now
return end_time - beginning_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