lua-users home
lua-l archive

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


I've done some testing with both approaches (LTN9 & concat.lua from
luasocket.)  Here are some (purely empirical) results:

-  If the lengths of the parts are distributed randomly over some interval
(e.g. lines from a text file) then both methods perform roughly the same (in
terms of created garbage.)  The maximum stack size for LTN9 is about 2 times
the stack size for concat.lua in this case.

-  In some pathological cases, LTN9 can perform _much_ worse, creating
several factors more garbage.  For example, concatenation of 50 strings of
lengths 50, 49, 48, ..., 1 generates 98 temporary strings with an average
size of ~226 bytes (LTN9) and 77 bytes (concat.lua) respectively.  For 500
strings of lengths 500, 499, 498, ..., 1 both create 998 temporary strings
with an average size of ~21001 bytes(LTN9) and ~1130 bytes (concat.lua)
respectively.  (LTN9 performs no "intermediate" concatenations in these
examples.)

-  It seems that choosing the factor in concat.lua between 1.3 and 1.4
(instead of 2) reduces the average garbage size still further.  I'm not sure
though, this would need some theoretical backup... (anyone?)  :-)

All considered, concat.lua is the better choice of the two.  The factor 2
can perhaps be tweaked a bit.

--
Wim