Last active
January 27, 2016 16:41
-
-
Save adymo/a62e502a1ff6afe714e0 to your computer and use it in GitHub Desktop.
Example of each_with_index iterator creating extra objects
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
GC.disable | |
before = ObjectSpace.count_objects | |
Array.new(10000).each do |i| | |
[0,1].each_with_index do |j, index| | |
end | |
end | |
after = ObjectSpace.count_objects | |
puts "# of arrays: %d" % (after[:T_ARRAY] - before[:T_ARRAY]) | |
puts "# of extra Ruby objects: %d" % (after[:T_NODE] - before[:T_NODE]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment