lua-users home
lua-l archive

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


> Hum, I don't know if your profiling or mine are wrong, but on my
> system (PII 300, Win98), the first routine
> is awful, 10 time slower than the second one.

It can get _much_ worse, depending on the size of the test range.  The
concat ".." (or the format call in this case) used in a loop is to blame for
that.  See Roberto's LTN 9 "Creating Strings Piece by Piece" for more info
and a solution for Lua 4.  In Lua 5 the table.concat function solves this
problem (of course LTN 9 is still valid.)

    http://www.lua.org/notes/ltn009.html

Although concatenating multiple parts with the ".." operator compiles into a
single CONCAT opcode, it looks like string.format still significantly
outperforms "..", certainly if not all the parts are constant.

And on a more trivial note: if you use table.insert in a loop, make it a
local first.  This saves two table lookups per iteration.

--
Wim