You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 1.9.3-p448
user system total real
95.690000 0.000000 95.690000 ( 95.876045)
111.440000 0.100000 111.540000 (111.837126)
explicit calls is 14.1% than send
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 2.0.0-p247
user system total real
76.520000 0.000000 76.520000 ( 76.650600)
102.940000 0.000000 102.940000 (103.093323)
explicit calls is 25.6% than send
def vs define_method
classAdefa;enddefine_method(:b){}end# For single method callBenchmark.bmdo |x|
x.report{100_000_000.times{A.new.b}}x.report{100_000_000.times{A.new.a}}end
Results
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 1.9.3-p448
user system total real
39.320000 0.000000 39.320000 ( 39.418881)
28.160000 0.010000 28.170000 ( 28.230322)
def is 28.4% faster than define_method
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 2.0.0-p247
user system total real
31.420000 0.000000 31.420000 ( 32.021655)
25.480000 0.000000 25.480000 ( 25.547244)
def if 20.4% faster than define_method
# For multiple method callsBenchmark.bmdo |x|
x.report{obj=A.new;100_000_000.times{obj.b}}x.report{obj=A.new;100_000_000.times{obj.a}}end
Results
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 1.9.3-p448
user system total real
17.720000 0.050000 17.770000 ( 17.815660)
9.280000 0.020000 9.300000 ( 9.307244)
def is 47.6% faster than define_method
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 2.0.0-p247
user system total real
12.770000 0.000000 12.770000 ( 12.823291)
7.890000 0.000000 7.890000 ( 7.910796)
def is 38.2 % faster than define_method
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 1.9.3-p448
user system total real
1.930000 0.010000 1.940000 ( 1.941696)
0.360000 0.000000 0.360000 ( 0.364693)
#method_missing with method definition is 81.2% faster.
# Ubuntu 13.04 64-bit
# Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
# RAM 7,7 GiB
# Ruby 2.0.0-p247
user system total real
2.090000 0.000000 2.090000 ( 2.104916)
0.330000 0.000000 0.330000 ( 0.331562)
#method_missing with method definition is 84.3% faster.
It's faster because #method_missing have been called only once.