lua-users home
lua-l archive

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


On Sunday 09 May 2004 14:32, Ashwin Hirschi wrote:
> >> 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...

Yeah, I wasn't thinking straight. The table version as I had it before would 
always have been slower than the if chain because of the construction 
overhead. I've changed the benchmark according to Michael's post, and the 
crossover point for amortized time is at about 10 options if you use a local 
table that's only contructed once (i.e. 5 options for worst-case 
performance). Quinn would have had slighly slower table accesses because he 
used a global table.

-- Jamie Webb