Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:8232978
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
module MA; end
module MB; end
module MC; end
module MD; end
module ME; end
 
class A; end
 
class B < A
include MA
include MB
include MC
include MD
include ME
end
 
class C < B; end
class D < C; end
 
require 'benchmark'
 
class A
100_000.times do |i|
define_method "a#{i}" do
1
end
end
end
 
@d = D.new
@a = A.new
 
methods = []
100_000.times{ |i| methods << "a#{i}".to_sym }
 
GC.disable
Benchmark.bm do |x|
x.report("flat") { 100_000.times{ |i| @a.send methods[i] } }
x.report("deep") { 100_000.times{ |i| @d.send methods[i] } }
end
View gist:8232978
1
chruby 2.0.0 && ruby dispatch.rb && chruby 2.1.0 && ruby dispatch.rb
View gist:8232978
1 2 3 4 5 6
user system total real
flat 0.030000 0.000000 0.030000 ( 0.031963)
deep 0.040000 0.000000 0.040000 ( 0.036419)
user system total real
flat 0.040000 0.000000 0.040000 ( 0.035921)
deep 0.040000 0.000000 0.040000 ( 0.041264)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.