Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # instances method
- def instances(&block)
- GC.enable_stats
- GC.clear_stats
- block.call
- warmup_objs = GC.num_allocations
- warmup_bytes = GC.allocated_size
- GC.clear_stats
- block.call
- puts "Objects:"
- puts "Warmup: #{warmup_objs} allocations | #{warmup_bytes} bytes"
- puts "Actual: #{GC.num_allocations} allocations | #{GC.allocated_size} bytes"
- end
- Account.destroy_all
- a = Account.create(:email => 'miloops@example.com')
- 50.times do |i|
- c = a.posts.create!(:title => "test", :body => "Loldel")
- 10.times do
- c.comments.create!(:body => ("lol! " * 10))
- end
- end
- Account.first.posts(:include => :comments).map{|c| c.comments}.flatten.each do |comment|
- comment.post.account.email
- end; nil
- instances do
- Account.first.posts(:include => :comments).map{|c| c.comments}.flatten.each do |comment|
- comment.post.account.email
- end
- end
- With IdentityMap disabled:
- Warmup: 563328 allocations | 20273094 bytes
- Actual: 562227 allocations | 20264239 bytes
- With IdentityMap enabled:
- Warmup: 116908 allocations | 3621494 bytes
- Actual: 21108 allocations | 390139 bytes
- Account.first(:include => {:posts => :comments}).posts.map(&:comments).flatten.each do |comment|
- comment.post.account.email
- end; nil
- instances do
- Account.first(:include => {:posts => :comments}).posts.map(&:comments).flatten.each do |comment|
- comment.post.account.email
- end
- end
- With IdentityMap disabled:
- Objects:
- Warmup: 553832 allocations | 19720865 bytes
- Actual: 553836 allocations | 19720860 bytes
- With IdentityMap enabled:
- Objects:
- Warmup: 18401 allocations | 254328 bytes
- Actual: 108517 allocations | 3078103 bytes
Add Comment
Please, Sign In to add comment