Skip to content

Instantly share code, notes, and snippets.

@kevinmcaleer
Created September 17, 2023 11:47
Show Gist options
  • Save kevinmcaleer/c631a3502d86106d0b8b501252d215a4 to your computer and use it in GitHub Desktop.
Save kevinmcaleer/c631a3502d86106d0b8b501252d215a4 to your computer and use it in GitHub Desktop.
GPIO Benchmarking tool
import time
from gpiozero import LED
# Setup
led = LED(17)
iterations = 100000 # Number of times the LED will be toggled on and off
# Benchmark
start_time = time.time()
for _ in range(iterations):
led.on()
led.off()
end_time = time.time()
# Calculate and display results
total_time = end_time - start_time
time_per_toggle = total_time / (iterations * 2) # Multiply by 2 for on and off
print(f"Total time for {iterations} toggles: {total_time:.6f} seconds")
print(f"Average time per toggle: {time_per_toggle:.10f} seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment