Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active January 2, 2016 01:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SamSaffron/8232978 to your computer and use it in GitHub Desktop.
Save SamSaffron/8232978 to your computer and use it in GitHub Desktop.
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
chruby 2.0.0 && ruby dispatch.rb && chruby 2.1.0 && ruby dispatch.rb
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