-
-
Save atnan/135037 to your computer and use it in GitHub Desktop.
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 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