Created
April 5, 2011 20:33
-
-
Save wtn/904482 to your computer and use it in GitHub Desktop.
modify array with << and delete instead of + and -
This file contains 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
ATTRIBUTES = %w{a b c d e f g h i j _id} | |
t0 = Time.now | |
100_000.times do | |
ATTRIBUTES.dup.map { |k| k.to_s } + ['id'] - ['_id'] | |
end | |
map_time = Time.now - t0 | |
t1 = Time.now | |
100_000.times do | |
acc = [] | |
ATTRIBUTES.dup.each { |k| acc << k.to_s } | |
acc << 'id' | |
acc.delete('_id') | |
acc | |
end | |
each_time = Time.now - t1 | |
savings_ratio = (map_time - each_time).to_f / map_time | |
puts "You saved #{"%.2f" % (savings_ratio * 100)}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment