Created
June 30, 2016 08:48
-
-
Save takkanm/4eef2970faf168c47f593ffa999d789e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
module Foo | |
def foo;end | |
end | |
times = 1_000_000 | |
Benchmark.bm 30 do |r| | |
r.report 'none' do | |
times.times do | |
o = Object.new | |
end | |
end | |
GC.start | |
r.report 'touch singleton_class' do | |
times.times do | |
o = Object.new | |
o.singleton_class | |
end | |
end | |
GC.start | |
r.report 'lookup' do | |
times.times do | |
o = Object.new | |
if o.singleton_class.ancestors.include? :hi | |
end | |
end | |
end | |
GC.start | |
r.report 'extend' do | |
times.times do | |
o = Object.new | |
o.extend Foo | |
end | |
end | |
GC.start | |
r.report 'singleton_class include' do | |
times.times do | |
o = Object.new | |
o.singleton_class.include Foo | |
end | |
end | |
GC.start | |
r.report 'singleton_class prepend' do | |
times.times do | |
o = Object.new | |
o.singleton_class.include Foo | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
none 0.140000 0.000000 0.140000 ( 0.139669) | |
touch singleton_class 1.180000 0.040000 1.220000 ( 1.228629) | |
lookup 1.700000 0.060000 1.760000 ( 1.788575) | |
extend 2.090000 0.050000 2.140000 ( 2.155467) | |
singleton_class include 2.090000 0.050000 2.140000 ( 2.142550) | |
singleton_class prepend 1.960000 0.020000 1.980000 ( 1.990201) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment