[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Convert bytes array to string
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 18 Mar 2002 10:00:21 -0300
> I try this test in
>
> [...]
>
> And in each case concatenation approach is faster.
>
> [...]
>
> Does anyone knows abount this?
Have you both agreed about how to test each solution? (I haven't seen
that on the messages...) On my machine, the concat solution is
faster than gsub for small arrays, but gsub gets better as the size
grows. This is expected, as the concat solution is ~O(n^2), see
http://www.lua.org/notes/ltn009.html.
With Lua w4, you can try the new "concat" function:
function bytestostring2 (bytes)
local w = {}
for i=1,getn(bytes) do w[i] = strchar(bytes[i]) end
return concat(w)
end
-- Roberto