Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of each_with_index iterator creating extra objects
before = ObjectSpace.count_objects do |i|
[0,1].each_with_index do |j, index|
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