> ruby n_bench.rb
user system total real
n = 10 ----------------------------------------------------------
in a class: 0.000000 0.000000 0.000000 ( 0.000366)
multi-use class: 0.000000 0.000000 0.000000 ( 0.000181)
multi-use object: 0.000000 0.000000 0.000000 ( 0.000144)
control case: 0.000000 0.000000 0.000000 ( 0.000012)
control in class: 0.000000 0.000000 0.000000 ( 0.000139)
control in object: 0.000000 0.000000 0.000000 ( 0.000018)
n = 100 ----------------------------------------------------------
in a class: 0.000000 0.000000 0.000000 ( 0.001526)
multi-use class: 0.000000 0.000000 0.000000 ( 0.000717)
multi-use object: 0.000000 0.000000 0.000000 ( 0.000149)
control case: 0.000000 0.000000 0.000000 ( 0.000049)
control in class: 0.000000 0.000000 0.000000 ( 0.000268)
control in object: 0.000000 0.000000 0.000000 ( 0.000094)
n = 1000 ----------------------------------------------------------
in a class: 0.030000 0.000000 0.030000 ( 0.032788)
multi-use class: 0.000000 0.000000 0.000000 ( 0.003178)
multi-use object: 0.010000 0.000000 0.010000 ( 0.001427)
control case: 0.000000 0.000000 0.000000 ( 0.000394)
control in class: 0.030000 0.000000 0.030000 ( 0.035087)
control in object: 0.000000 0.000000 0.000000 ( 0.000831)
n = 10000 ----------------------------------------------------------
in a class: 0.400000 0.010000 0.410000 ( 0.409498)
multi-use class: 0.150000 0.000000 0.150000 ( 0.155968)
multi-use object: 0.030000 0.000000 0.030000 ( 0.026565)
control case: 0.010000 0.000000 0.010000 ( 0.003869)
control in class: 0.070000 0.000000 0.070000 ( 0.074177)
control in object: 0.020000 0.000000 0.020000 ( 0.020634)
n = 100000 ----------------------------------------------------------
in a class: 4.450000 0.040000 4.490000 ( 4.508097)
multi-use class: 1.240000 0.000000 1.240000 ( 1.242558)
multi-use object: 0.140000 0.000000 0.140000 ( 0.144972)
control case: 0.040000 0.000000 0.040000 ( 0.039157)
control in class: 0.830000 0.000000 0.830000 ( 0.837038)
control in object: 0.100000 0.000000 0.100000 ( 0.097637)
RANK: n = 100000 n = 10
--------------------------------------------------------------------------
6. #in_class 11513% 3050%
5. #in_missing_class 3173% 1508%
4. #in_missing_class CONTROL (except for n=10) 2138% 1158%
3. #in_missing_object 370% 1200%
2. #in_missing_object CONTROL 249% 150%
1. #call 100% 100%
So #in_missing_object is best case nearly 4 times slower than ordinary proc params and worst case around 12 times slower, and performs better when ran multiple times.
> ruby a_bench.rb
user system total real
a.size = 1 ----------------------------------------------------------
in a class: 0.040000 0.000000 0.040000 ( 0.044814)
multi-use class: 0.010000 0.000000 0.010000 ( 0.002935)
multi-use object: 0.000000 0.000000 0.000000 ( 0.001318)
control case: 0.000000 0.000000 0.000000 ( 0.000418)
control in class: 0.010000 0.000000 0.010000 ( 0.017274)
control in object: 0.010000 0.000000 0.010000 ( 0.000818)
a.size = 10 ----------------------------------------------------------
in a class: 0.100000 0.010000 0.110000 ( 0.102900)
multi-use class: 0.000000 0.000000 0.000000 ( 0.002817)
multi-use object: 0.000000 0.000000 0.000000 ( 0.001272)
control case: 0.010000 0.000000 0.010000 ( 0.000398)
control in class: 0.000000 0.000000 0.000000 ( 0.002198)
control in object: 0.000000 0.000000 0.000000 ( 0.000885)
a.size = 100 ----------------------------------------------------------
in a class: 0.700000 0.020000 0.720000 ( 0.723531)
multi-use class: 0.000000 0.000000 0.000000 ( 0.002969)
multi-use object: 0.000000 0.000000 0.000000 ( 0.001269)
control case: 0.000000 0.000000 0.000000 ( 0.000401)
control in class: 0.010000 0.000000 0.010000 ( 0.002075)
control in object: 0.000000 0.000000 0.000000 ( 0.000820)
a.size = 1000 ----------------------------------------------------------
in a class: 7.200000 0.240000 7.440000 ( 7.474116)
multi-use class: 0.000000 0.000000 0.000000 ( 0.003311)
multi-use object: 0.010000 0.000000 0.010000 ( 0.001321)
control case: 0.000000 0.000000 0.000000 ( 0.000402)
control in class: 0.000000 0.000000 0.000000 ( 0.002355)
control in object: 0.000000 0.000000 0.000000 ( 0.000959)
RANK: a = 1000 a = 1
--------------------------------------------------------------------------
6. #in_class 1859233% 10721%
4. #in_missing_class 824% 702%
5. #in_missing_class CONTROL 585% 4133%
3. #in_missing_object 329% 315%
2. #in_missing_object CONTROL 239% 196%
1. #call 100% 100%
So again we find that #in_missing_object is still the best in terms of handling various numbers of arguments, and that #in_class (as each is being defined as a method is slowest).