Skip to content

Instantly share code, notes, and snippets.

@joshmvandercom
Created January 10, 2011 22:55
Show Gist options
  • Save joshmvandercom/773639 to your computer and use it in GitHub Desktop.
Save joshmvandercom/773639 to your computer and use it in GitHub Desktop.
Calculate Execution time
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