Last active
June 23, 2016 18:42
-
-
Save FioFiyo/6b2a73139d4be1f99d09a6c75fd433dd to your computer and use it in GitHub Desktop.
Cleaner code to run the block perhaps faster?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require 'pry' | |
def benchmark | |
start_time = Time.now | |
# binding.pry | |
yield | |
end_time = Time.now | |
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