lua-users home
lua-l archive

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

On Thu, May 14, 2009 at 1:41 AM, Daniel Ng <> wrote:
> I'm running lua 5.1.3 on a Linux 2.6 uClibc system.
> My Lua script writes to an SPI driver 256 bytes at a time. Unfortunately the
> time it takes to get the 256 bytes to the driver is almost 2 seconds!
> I need this to write about 2MB of data in total, so this rate is unfortunately
> not acceptable.
> Please have a look below at a description of the script. Am I doing too much
> memory copying? Or could it be something else?

It's unlikely that lua's string handling is a problem here, unless
write_format() is doing something crazy.

That said, your spiExchangeBytes could take a string as an arg, as
well as an offset and length into that string. This would avoid all
the memory copying. This is what luasocket does, for example, in

And it's not clear at all why you are use write_format(). You are
sending a large string, not packing integers into a string, right?

The easy way to instrument this to see how long it's taking is to
replace spiExchangeBytes with a stub that returns succcess, and time
the entire operation. If it takes a few 100 ms, then you know where
the problem is.