Guest User

Untitled

a guest
Jun 24th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. # instances method
  2. def instances(&block)
  3. GC.enable_stats
  4. GC.clear_stats
  5. block.call
  6. warmup_objs = GC.num_allocations
  7. warmup_bytes = GC.allocated_size
  8. GC.clear_stats
  9. block.call
  10. puts "Objects:"
  11. puts "Warmup: #{warmup_objs} allocations | #{warmup_bytes} bytes"
  12. puts "Actual: #{GC.num_allocations} allocations | #{GC.allocated_size} bytes"
  13. end
  14.  
  15.  
  16. Account.destroy_all
  17.  
  18. a = Account.create(:email => 'miloops@example.com')
  19. 50.times do |i|
  20. c = a.posts.create!(:title => "test", :body => "Loldel")
  21. 10.times do
  22. c.comments.create!(:body => ("lol! " * 10))
  23. end
  24. end
  25.  
  26.  
  27. Account.first.posts(:include => :comments).map{|c| c.comments}.flatten.each do |comment|
  28. comment.post.account.email
  29. end; nil
  30.  
  31. instances do
  32. Account.first.posts(:include => :comments).map{|c| c.comments}.flatten.each do |comment|
  33. comment.post.account.email
  34. end
  35. end
  36.  
  37. With IdentityMap disabled:
  38.  
  39. Warmup: 563328 allocations | 20273094 bytes
  40. Actual: 562227 allocations | 20264239 bytes
  41.  
  42. With IdentityMap enabled:
  43.  
  44. Warmup: 116908 allocations | 3621494 bytes
  45. Actual: 21108 allocations | 390139 bytes
  46.  
  47.  
  48.  
  49. Account.first(:include => {:posts => :comments}).posts.map(&:comments).flatten.each do |comment|
  50. comment.post.account.email
  51. end; nil
  52.  
  53. instances do
  54. Account.first(:include => {:posts => :comments}).posts.map(&:comments).flatten.each do |comment|
  55. comment.post.account.email
  56. end
  57. end
  58.  
  59. With IdentityMap disabled:
  60.  
  61. Objects:
  62. Warmup: 553832 allocations | 19720865 bytes
  63. Actual: 553836 allocations | 19720860 bytes
  64.  
  65.  
  66. With IdentityMap enabled:
  67.  
  68. Objects:
  69. Warmup: 18401 allocations | 254328 bytes
  70. Actual: 108517 allocations | 3078103 bytes
Add Comment
Please, Sign In to add comment