Hi all,
regarding execution speed on the target (LPC2478, 72MHz) I've got a question: Toggling a pin[1] on the target takes - ~12ms using two RPC calls from the PC - ~280µs using one RPC call of a 'transferred' toggling function - ~280µs using cross-compiled Lua code on the target (This corresponds to ~20000 target instructions.) Are these values reasonable or can they be somehow improved? It seems that each 'peripheral call' (pio, tmr, etc.) has an inherent delay of 50-100µs on the target, e.g. adding a tmr.delay(0,0) call[2] before setting the pin low adds another ~70µs before the pin is reset. ,----[ 1 ] | function toggle_flag() | pio.pin.sethigh(pio.P3_31) | pio.pin.setlow(pio.P3_31) | end `---- ,----[ 2 ] | function toggle_flag() | pio.pin.sethigh(pio.P3_31) | tmr.delay(0, 0) | pio.pin.setlow(pio.P3_31) | end `---- Regards, Markus Korber _______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Hi,
On Thu, Dec 15, 2011 at 9:22 AM, Markus Korber <[hidden email]> wrote: Hi all, There are some things that can be done in this area: 1. currently, eLua is compiled for space optimizations only (-Os). Switching to speed optimizations will probably improve things.
2. functions like getpin/setpin can be made smaller to get more speed. That said, don't expect significant performance improvements. You'd need a JIT for that.
Best, Bogdan
_______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Martin Guy |
In reply to this post by Markus Korber
On 15 December 2011 08:22, Markus Korber <[hidden email]> wrote:
> regarding execution speed on the target (LPC2478, 72MHz) I've got a > question: Toggling a pin[1] on the target takes > > - ~12ms using two RPC calls from the PC > - ~280µs using one RPC call of a 'transferred' toggling function > - ~280µs using cross-compiled Lua code on the target (This > corresponds to ~20000 target instructions.) > > Are these values reasonable or can they be somehow improved? > > It seems that each 'peripheral call' (pio, tmr, etc.) has an inherent > delay of 50-100µs on the target, e.g. adding a tmr.delay(0,0) call[2] > before setting the pin low adds another ~70µs before the pin is reset. > > ,----[ 1 ] > | function toggle_flag() > | pio.pin.sethigh(pio.P3_31) > | pio.pin.setlow(pio.P3_31) > | end > `---- > > ,----[ 2 ] > | function toggle_flag() > | pio.pin.sethigh(pio.P3_31) > | tmr.delay(0, 0) > | pio.pin.setlow(pio.P3_31) > | end > `---- Hi You can speed your Lua code by the usual tricks, for example, putting things in locals: local sethigh = pio.pin.sethigh local setlow = pio.pin.setlow local pin = pio.P3_31 function toggle_flag() sethigh(pin) setlow(pin) end since global table lookups are much slower than locals, which live in virtual machine registers. You're doubly stung in this case by the API: pio.pin.sethigh() takes two table lookups, whereas the original interface, pio.sethigh(), only needed one. Then there is the pio.P3_31 table lookup every time round the loop, whereas a the more Lua-like use of strings as parameters, e.g. pio.sethigh("P3_31") is faster since strings with the same contents are commoned in the interpreter, so comparison between constant strings is just a pointer comparison at runtime. In this case, "P3_31", the string would be constant and its contents processed with a tiny piece of C at runtime in a few cycles - still much faster than a table lookup But to implement this you would need to fork eLua. M _______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Markus Korber |
In reply to this post by BogdanM
Thus spake Bogdan Marinescu:
> On Thu, Dec 15, 2011 at 9:22 AM, Markus Korber <[hidden email]> wrote: > >> regarding execution speed on the target (LPC2478, 72MHz) I've got a >> question: Toggling a pin[1] on the target takes >> >> [Timing measurments] >> >> Are these values reasonable or can they be somehow improved? > > There are some things that can be done in this area: > > 1. currently, eLua is compiled for space optimizations only (-Os). > Switching to speed optimizations will probably improve things. Sorry, I forgot to mention that I'm compiling with -O2 already. > 2. functions like getpin/setpin can be made smaller to get more speed. Do you mean the platform code in platform_pio_op()? > That said, don't expect significant performance improvements. You'd need a > JIT for that. Ok, thanks for your hints. Regards, Markus Korber _______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Markus Korber |
In reply to this post by Martin Guy
Thus spake Martin Guy:
> On 15 December 2011 08:22, Markus Korber <[hidden email]> wrote: >> regarding execution speed on the target (LPC2478, 72MHz) I've got a >> question: Toggling a pin[1] on the target takes > >> [Timing measrements] >> Are these values reasonable or can they be somehow improved? > > You can speed your Lua code by the usual tricks, for example, > putting things in locals: > > local sethigh = pio.pin.sethigh > local setlow = pio.pin.setlow > local pin = pio.P3_31 > function toggle_flag() > sethigh(pin) > setlow(pin) > end > > since global table lookups are much slower than locals, which live in > virtual machine registers. Interesting. That improved the toggling time to below 20µs (factor 15!). I guess I can live with that. Thanks. > [Enlightning explanation snipped] Thanks for your help. Regards, Markus Korber _______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Hi guys,
I want to run some execution time tests on my code. How can I get the most accurate measurements? thanks for your help ;-) |
Martin Guy |
On 12 June 2012 00:08, agostain <[hidden email]> wrote:
> I want to run some execution time tests on my code. How can I get the most > accurate measurements? I use the tmr module, accelerating the setup/teardown with locals, something like: -- speed test for uart writes: see how long sending a 1000 characters takes. do local p = io.write local r = tmr.read local gdn = tmr.getdiffnow local s = r() for i=1,1000 do p("U") end p(gdn(nil, s)) end M _______________________________________________ eLua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Free forum by Nabble | Edit this page |