Skip to content

Instantly share code, notes, and snippets.

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