Closed gw0 closed 8 years ago
Yes, this is to be expected when re-instantiating/re-opening the GPIO on each read. There are a handful of system calls that take place to ensure the GPIO is available (and exported if it's not) and setting direction, before its value
file is opened for actual reading or writing. You can find these calls in https://github.com/vsergeev/c-periphery/blob/master/src/gpio.c#L57 and observe them with strace
.
Our best bet is to root cause and fix issue #10, as there is not much that can be done to improve the open/close paths.
I'm closing this issue for now, but will re-open if it becomes relevant to Issue #10.
Yes, leaving file descriptors open and caching them could speed things up, but would increase memory usage. But it seems that there is also a lot of overhead for calling C functions from Lua.
Otherwise, I also implemented both variants (one open per read, and open once and read multiple times) also in ANSI C. Both were a little bit faster (~70%) than pure Lua implementations, but still not fast enough for my sampling needs.
I was benchmarking the speed of reading GPIO ports in different ways, and with lua-periphery it is extremely slow (using one open per read, because of #10).
/sys/..
file reading (using one open per read): real 0m 8.80s, user 0m 3.83s, sys 0m 4.92s/sys/..
file reading (open once, read and seek multiple times): real 0m 5.26s, user 0m 3.08s, sys 0m 2.18s