lua-users home
lua-l archive

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


There have been a few posts comparing the timing of while,
ipairs, numeric for with and without the length operator on various
systems by running loops that do only a couple of additions inside.

Am I the only one who thinks that this sort of test is like
putting some cars in neutral, have them idle for a couple
of hours, and measure their fuel consumption?

The moment some real work is done inside the loop, the
efficiency difference of the loop structure itself (which anyway
according to the reports seems to be very system-dependent)
pales into insignificance.

For example, on my system (local 32-bit Ubuntu build from the latest
source releases) `while` was fastest, at about 0.5 seconds and ipairs
slowest at about 1.3 seconds.

I replaced the line

    sum = sum + j + v

by

    sum = tostring(v):upper()

and the time jumps to about 15 seconds.  On LuaJIT it jumped
from 0.3 to to 136 seconds.  I could have got myself a mug of
coffee.  Bye-bye to the conventional wisdom that LuaJIT is
faster than PUC-Rio!