lua
-------------------------------------------------------------------
name | rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
args_hard_simple | 1.0000 | 11.38 / 10000000 = 1.138000 us
plain_assert | 1.0255 | 11.67 / 10000000 = 1.167000 us
assert_is | 1.1090 | 12.62 / 10000000 = 1.262000 us
args_unroll_simple | 1.4042 | 15.98 / 10000000 = 1.598000 us
args_select_simple | 1.6380 | 18.64 / 10000000 = 1.864000 us
args_recursive_simp | 1.7469 | 19.88 / 10000000 = 1.988000 us
args_recursive_ln | 1.8225 | 20.74 / 10000000 = 2.074000 us
assert_is_alloc | 2.0905 | 23.79 / 10000000 = 2.379000 us
luajit2
-------------------------------------------------------------------
name | rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
plain_assert | nan | 0.00 / 10000000 = 0.000000 us
assert_is_alloc | nan | 0.00 / 10000000 = 0.000000 us
assert_is | nan | 0.00 / 10000000 = 0.000000 us
args_hard_simple | nan | 0.00 / 10000000 = 0.000000 us
args_unroll_simple | inf | 2.22 / 10000000 = 0.222000 us
args_select_simple | inf | 3.25 / 10000000 = 0.325000 us
args_recursive_simp | inf | 3.48 / 10000000 = 0.348000 us
args_recursive_ln | inf | 3.56 / 10000000 = 0.356000 us
The question is: can LJ2 be made to optimize the function below away? (That's what args_unroll_simple is.)
local arguments = function(...)
local n = select("#", ...)
-- Assuming cache is pre-populated for all possible use-cases
return assert(arguments_cache[n])(...)
end