lua-users home
lua-l archive

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


Probably the lua version has nothing to do with that.

What happens is that your algorithm is faster for small byte sequences (lets say, 10, 100 bytes) and Eric's is faster for larger
sequences.

This is because Eric's code has a startup time larger than your's (calling strrep, defining a function inside the function and,
possibly, the secrets that goes inside gsub itself).

If you're worried about performance, you may want to use the 2 algorithms. You'll need to write some tests to "calibrate" for best
performance (determining the region -- number of bytes -- in which one code is faster than the other) and write a function that
chooses the best alternative. This region may be platform dependent and lua version dependent.

If you want to be sure that this part of your code is really the responsible for slowness, you can use the LuaProfiler (it's in the
wiki)

Luiz.

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of SATO Seichi
> Sent: Sunday, March 17, 2002 12:08 AM
> To: Multiple recipients of list
> Subject: Re: Convert bytes array to string
>
>
> I try this test in
>
> 1) Lua 4.0 on Darwin 5.3
> 2) Lua 4.0 on Debian GNU/Linux 2.2
> 3) Lua 4.1w4 on Darwin 5.3
> 4) Lua 4.1w4 on Debian GNU/Linux 2.2
>
> And in each case concatenation approach is faster.
>
> So piece together with the disagreement with Eric's result,
> I think Lua 4.1w4 makes some platform dependent optimization
> around gsub function.
>
> Does anyone knows abount this?
>
> --
> SATO Seichi
>