Created
January 7, 2022 21:33
-
-
Save chingsley/d10b84352a401f3c5c6f799e5c9b87c7 to your computer and use it in GitHub Desktop.
benchmarking with blocks in ruby
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(&block) | |
start_time = Time.now | |
block.call | |
end_time = Time.now | |
return end_time - start_time | |
end | |
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