5

Benchmarking of the Pi 4 using the Python GPIO Zero library shows a significant increase in the frequency of toggling a GPIO pin on and off compared to previous models. This result is attributed to the higher CPU speed.

enter image description here source

Other benchmarks, e.g. Raspberry Pi 2 vs. 1 GPIO Benchmark however show a large range of results depending on the language / library. These numbers are substantially higher than those reported for the Python GPIO Zero library.

How does the Pi 4 GPIO perform using the different libraries (with a focus on C and the respective Python wrappers but other languages are also welcome)?

2
  • Every library and language will be different. Are you asking us to benchmark them all for you? If you want to know how fast the hardware can toggle then you have to look at the specs and my guess is that no library in a general purpose OS will get even close to that speed due to all the overhead they add. Commented Sep 30, 2020 at 16:04
  • 2
    @GoswinvonBrederlow nobody is forcing you to provide answers or contribute any content here, it is in fact completely up to you. So no, I am not asking you to benchmark any or all of them. If someone, however, has done any experiments to that end and is willing to post an answer that would be appreciated. After all that is the purpose of an Q&A.
    – Ghanima
    Commented Sep 30, 2020 at 21:04

3 Answers 3

2

I know this is an old question but it popped up on "Related" on a Question and was not answered.
I have a set of tests - not particularly good as a benchmark and the faster results vary between runs.

Raspberry Pi 4 Model B Rev 1.1  64 bit
pi-gpio C       11,855,364 toggles per second
bench_ioctl C      261,478 toggles per second
lgpio   C          395,532 toggles per second
RPi.GPIO Python  1,039,790 toggles per second
pi_gpio Python     380,408 toggles per second
lgpio Python       176,048 toggles per second
gpiod Python       109,536 toggles per second
gpiozero Python     30,416 toggles per second
pigpiod C           10,141 toggles per second
pigpiod Python       8,535 toggles per second
2
  • Is it possible to see the code?
    – Andrea
    Commented Jul 24, 2024 at 15:54
  • @Andrea None of it is private - it is all open source like all my code, many minor mods to published code. I have published some of the code in various places but there are 22 files (including scripts) and is only 80k but this is hardly the right place to put lots of files. It isn't worth creating a GitHub for such trivial code. Was there any particular item of interest?
    – Milliways
    Commented Jul 28, 2024 at 7:47
1

May not be a complete answer to your question but useful to know.

If you really need fast GPIO or GPIO which is "real time" (meaning that you can guarantee, for example, how long a signal stays high / goes low for, then you should not be using a non-RTOS (Real Time OS) device, such as a Raspberry Pi with Linux kernel. (Or if you need particularly "regular" [in time] signals, such as those used for clock signals, which you cannot achieve with a non-RTOS device.)

While there are "real time OS" kernels available for Linux, this is still only a "regular" linux kernel with higher rate of context switching.

If you need higher GPIO performance you have two options:

Use something like SPI interface on the Pi or I2C. (Or even UART.) These (probably) have specific hardware circuitry to support higher rates of data transfer than can be achieved with just general purpose IO which is slow.

Your alternatives to this are:

  • Use a microcontroller, which is a realtime device.

  • Use something like an FPGA, which is programmable digital logic and is not only realtime but also a truly parallel IO device.

I suspect you are in a similar situation to myself about 6-7 years ago where I worked on a project involving R-Pi's and I was not able to get high enough rates of IO from the GPIO to interface with things like ADCs. (Even at audio frequencies.)

-1

I'd expect the speeds to be about the same; any difference would be minuscule and barely noticeable for most applications. C is probably the best for controlling pins, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.