Created
January 10, 2011 22:55
-
-
Save joshmvandercom/773639 to your computer and use it in GitHub Desktop.
Calculate Execution time
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 execution_time | |
start = Time.now | |
yield | |
puts Time.now - start # Here you would probably log the elapsed time | |
end | |
execution_time do | |
1.upto(10000) do |i| | |
i * 1 # LIke a for loop | |
end | |
end | |
#Equivalent to - | |
start = Time.now | |
1.upto(10000) do |i| | |
i * 1 | |
end | |
puts Time.now - start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment