Forked from davidvandusen/benchmark_with_block.rb
Last active
April 28, 2016 16:05
-
-
Save adrimolano/7c7e4bda5b11f17f56130b5d364c30c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| beginning_time = Time.now | |
| yield | |
| end_time = Time.now | |
| running_time = 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