lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2014-11-20 17:03 GMT+00:00 Thiago L. <fakedme@gmail.com>:
> On 20/11/14 01:33 PM, Jerome Vuarand wrote:
>> You can always wrap a callable in a function, and a function is both
>> type-testable and always callable. So if you need a testable callable,
>> just wrap your object in a function. Given how easy that solution is,
>> you'll need more than a "please" to get that kind of feature. Where
>> are use cases, stats, benchmarks?
>
> Ok so...
>
> [pointless benchmark skipped]

These are benchmarks, but not for what I suggested. Why do you add (at
worst) a function creation or (at best) a table index to each
iteration when none of these are necessary?

Instead of:

t = setmetatable({},{__call = function(...) end})

You write:

local t0 = setmetatable({},{__call = function(...) end})
t = function(...) return t0(...) end

and then you use t exactly the same way in both cases. That's what you
should benchmark. And that is only half of the work, since you still
have to give any convincing argument regarding how often the kind of
optimization you suggest would benefit anybody.