lua-users home
lua-l archive

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



The above use of tables with functions to emulate switches caught my eye,
so I tried it with a long if ... elseif ... end chain (well, 8 choices ...
not so long, and I used a global rather than local table for the choices),
and it turned out to profile exactly the same speed as the if ... elseif ..
end chain. (The local table version was about 1 ms. slower for my test.)

Mmm, you're right. Looks like you need a few hundred options beforethe table method actually becomes faster.

Eh, are you guys serious? The dispatching through a table is definitely a lot faster than the if-elseif-end approach on a simple 6-option benchmark I'm running here...

I'm wondering: are your benchmarks actually distributing the possible dispatch values evenly and not hitting one of the 1st tests in the if-elseif-end construct all the time?

Ashwin.
--
no signature is a signature