Created
May 27, 2016 17:26
-
-
Save j0ni/dac2da8df3d7d1b282c8e50dff427510 to your computer and use it in GitHub Desktop.
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
# step 1 - eval apple*x and assign to long_string | |
long_string = "apple"*100000000 | |
# step 2 - define method benchmark | |
def benchmark | |
before = Time.now.to_i | |
yield # step 4 - evaluate the block | |
Time.now.to_i - before # step 5 - return the time | |
end | |
# step 3 - call benchmark with a block | |
running_time = benchmark { long_string.reverse } # step 6 - assign value to running_time | |
puts running_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment