Created
October 1, 2015 18:04
-
-
Save RobertCam/b7014434606f590288da to your computer and use it in GitHub Desktop.
benchmark method using yield to pass block
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
def benchmark | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
run_time = end_time - start_time | |
end | |
long_string = "apple"*100000000 | |
stupid_math = 1 + 1 * 1000 - 54 * 345 | |
running_time = benchmark { long_string.reverse } | |
running_time2 = benchmark { stupid_math } | |
puts "string.reverse took #{running_time} seconds to run" | |
puts "stupid math took #{running_time2} seconds to run" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment