Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. module A
  4. end
  5.  
  6. class B
  7. include A
  8. end
  9.  
  10. class C < B
  11. end
  12.  
  13. # Benchmarks for various module operations.
  14. #
  15. # user system total real
  16. # object_id (control) 0.230000 0.000000 0.230000 ( 0.234879)
  17. # [] (control) 0.380000 0.000000 0.380000 ( 0.379503)
  18. # ancestors C<B.A 0.650000 0.000000 0.650000 ( 0.658281)
  19. # ancestors B.A 0.610000 0.010000 0.620000 ( 0.623774)
  20. # ancestors A 0.530000 0.000000 0.530000 ( 0.542385)
  21. # superclass C<B.A 0.240000 0.000000 0.240000 ( 0.241200)
  22. # superclass B.A 0.240000 0.000000 0.240000 ( 0.249191)
  23. # inc_mod C<B.A 0.570000 0.010000 0.580000 ( 0.573147)
  24. # inc_mod B.A 0.550000 0.000000 0.550000 ( 0.564256)
  25. # inc_mod A 0.520000 0.000000 0.520000 ( 0.523128)
  26. # C.kind_of?(A) 0.310000 0.000000 0.310000 ( 0.308133)
  27. # B.kind_of?(A) 0.310000 0.000000 0.310000 ( 0.308827)
  28. # A.kind_of?(A) 0.300000 0.000000 0.300000 ( 0.299264)
  29. #
  30. # Much of the time required for ancestors appears associated with the
  31. # creation of an array.
  32. Benchmark.bm(20) do |x|
  33.  
  34. n = 1000000
  35.  
  36. x.report "object_id (control)" do
  37. n.times { C.object_id }
  38. end
  39.  
  40. x.report "[] (control)" do
  41. n.times { [] }
  42. end
  43.  
  44. x.report "ancestors C<B.A" do
  45. n.times { C.ancestors }
  46. end
  47.  
  48. x.report "ancestors B.A" do
  49. n.times { B.ancestors }
  50. end
  51.  
  52. x.report "ancestors A" do
  53. n.times { A.ancestors }
  54. end
  55.  
  56. x.report "superclass C<B.A" do
  57. n.times { C.superclass }
  58. end
  59.  
  60. x.report "superclass B.A" do
  61. n.times { B.superclass }
  62. end
  63.  
  64. x.report "inc_mod C<B.A" do
  65. n.times { C.included_modules }
  66. end
  67.  
  68. x.report "inc_mod B.A" do
  69. n.times { B.included_modules }
  70. end
  71.  
  72. x.report "inc_mod A" do
  73. n.times { A.included_modules }
  74. end
  75.  
  76. x.report "C.kind_of?(A)" do
  77. n.times { C.kind_of?(A) }
  78. end
  79.  
  80. x.report "B.kind_of?(A)" do
  81. n.times { B.kind_of?(A) }
  82. end
  83.  
  84. x.report "A.kind_of?(A)" do
  85. n.times { A.kind_of?(A) }
  86. end
  87. end
Add Comment
Please, Sign In to add comment