Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. require "benchmark/memory"
  2.  
  3. class A
  4. def self.class_method
  5. puts 'hello'
  6. end
  7. def instance_method
  8. puts 'hello'
  9. end
  10. end
  11.  
  12. Benchmark.memory do |x|
  13. x.report("class_method") { A.class_method }
  14. x.report("instance_method") { A.new.instance_method }
  15.  
  16. x.compare!
  17. end
  18.  
  19. #Calculating -------------------------------------
  20. #hello
  21. # class_method 40.000 memsize ( 0.000 retained)
  22. # 1.000 objects ( 0.000 retained)
  23. # 1.000 strings ( 0.000 retained)
  24. #hello
  25. # instance_method 80.000 memsize ( 0.000 retained)
  26. # 2.000 objects ( 0.000 retained)
  27. # 1.000 strings ( 0.000 retained)
  28. #
  29. #Comparison:
  30. # class_method: 40 allocated
  31. # instance_method: 80 allocated - 2.00x more
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement