lua-users home
lua-l archive

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


>> On 30 Mar 2018, at 05:04, Petri Häkkinen <petrih3@gmail.com> wrote:
>> 
>> On 29 Mar 2018, at 13.01, Duane Leslie <parakleta@darkreality.org> wrote:
>> 
>> They do have different semantics, but I believe you can implement everything you've proposed directly in Lua with equivalent performance (some small constant overhead for the VM) except maybe for the resize function.
> 
> “Equivalent performance”? “Small constant overhead"? Please.
> 
> Here are the relevant benchmarks using regular Lua tables, your Lua emulated arrays (with bugs fixed) and native arrays:
> 
> Running benchmarks using Lua emulated arrays...
> Insert           2.492200s
> Push             3.522455s
> Length           0.643619s

Well it is constant, but I was wrong about the small.  All of this cost is in the `__newindex` method, what happens if you take out the error checking (I only added that as an afterthought for parity with your described behaviour)?  I also wonder if using `self[] = mmax(self[], k)` is faster than the if-then.

Out of curiosity, using your benchmarks at what size table does the native length operation exceed my manual lookup metamethod?

Regards,

Duane.