Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- module A
- end
- class B
- include A
- end
- class C < B
- end
- # Benchmarks for various module operations.
- #
- # user system total real
- # object_id (control) 0.230000 0.000000 0.230000 ( 0.234879)
- # [] (control) 0.380000 0.000000 0.380000 ( 0.379503)
- # ancestors C<B.A 0.650000 0.000000 0.650000 ( 0.658281)
- # ancestors B.A 0.610000 0.010000 0.620000 ( 0.623774)
- # ancestors A 0.530000 0.000000 0.530000 ( 0.542385)
- # superclass C<B.A 0.240000 0.000000 0.240000 ( 0.241200)
- # superclass B.A 0.240000 0.000000 0.240000 ( 0.249191)
- # inc_mod C<B.A 0.570000 0.010000 0.580000 ( 0.573147)
- # inc_mod B.A 0.550000 0.000000 0.550000 ( 0.564256)
- # inc_mod A 0.520000 0.000000 0.520000 ( 0.523128)
- # C.kind_of?(A) 0.310000 0.000000 0.310000 ( 0.308133)
- # B.kind_of?(A) 0.310000 0.000000 0.310000 ( 0.308827)
- # A.kind_of?(A) 0.300000 0.000000 0.300000 ( 0.299264)
- #
- # Much of the time required for ancestors appears associated with the
- # creation of an array.
- Benchmark.bm(20) do |x|
- n = 1000000
- x.report "object_id (control)" do
- n.times { C.object_id }
- end
- x.report "[] (control)" do
- n.times { [] }
- end
- x.report "ancestors C<B.A" do
- n.times { C.ancestors }
- end
- x.report "ancestors B.A" do
- n.times { B.ancestors }
- end
- x.report "ancestors A" do
- n.times { A.ancestors }
- end
- x.report "superclass C<B.A" do
- n.times { C.superclass }
- end
- x.report "superclass B.A" do
- n.times { B.superclass }
- end
- x.report "inc_mod C<B.A" do
- n.times { C.included_modules }
- end
- x.report "inc_mod B.A" do
- n.times { B.included_modules }
- end
- x.report "inc_mod A" do
- n.times { A.included_modules }
- end
- x.report "C.kind_of?(A)" do
- n.times { C.kind_of?(A) }
- end
- x.report "B.kind_of?(A)" do
- n.times { B.kind_of?(A) }
- end
- x.report "A.kind_of?(A)" do
- n.times { A.kind_of?(A) }
- end
- end
Add Comment
Please, Sign In to add comment