Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atnan/135037 to your computer and use it in GitHub Desktop.
Save atnan/135037 to your computer and use it in GitHub Desktop.
def measure_time task_description
beginning = Time.now
yield
puts "Time to #{task_description}: #{Time.now - beginning} seconds"
end
def add a, i
a << i
end
5.times do
measure_time("add item via method") do
a = []
1000000.times {|i| add a, i}
end
end
5.times do
measure_time("add item via method") do
a = []
1000000.times {|i| a << i}
# puts "length #{a.length}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment