Hi Gregor,
how did you measure the timing?
as CircuitPython is an interpreted language - and the interpretation is done on this little micro-controller it is *normal* that the resulting speed is *slow*.
for the most beginner use-cases it is fast enough... ;-)
i currently have no osci on hand - so i can not tell how fast things move in real -
i just run this speedtest code (orig. from another project therefore way more complicated then needed...):
Code: Select all
# SPDX-FileCopyrightText: 2023 s-light.eu Stefan Krüger
# SPDX-License-Identifier: MIT
import time
import board
import digitalio
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
def speed_test(fn, msg, count=1000):
print("{} speed test running..".format(msg))
start = time.monotonic()
for i in range(count):
fn()
end = time.monotonic()
duration = (end - start) / count
duration_ms = duration * 1000
result = {
"msg": msg,
"duration_ms": duration_ms,
}
print(
"'{}' needs {:10.3f}ms/call".format(
result["msg"],
result["duration_ms"],
)
)
return result
def print_results(speed_tests):
msg_max_length = max(len(x["msg"]) for x in speed_tests)
# print(msg_max_length)
for test in speed_tests:
msg_template = (
"'{:<" + "{}".format(msg_max_length + 5) + "}' needs {:10.3f}ms/call"
)
print(
msg_template.format(
test["msg"],
test["duration_ms"],
)
)
print("\n" * 20)
speed_tests = []
if hasattr(board, "DISPLAY"):
import displayio
print("deactivate display..")
board.DISPLAY.auto_refresh = False
board.DISPLAY.root_group = displayio.Group()
def toggle_led():
led.value = not led.value
speed_tests.append(
speed_test(
toggle_led,
msg="toggle_led",
count=100000,
)
)
if hasattr(board, "DISPLAY"):
print("activate display..")
board.DISPLAY.auto_refresh = True
board.DISPLAY.root_group = displayio.CIRCUITPYTHON_TERMINAL
print("\n" * 20)
time.sleep(1)
print_results(speed_tests)
time.sleep(1)
print("done...")
it results in
Code: Select all
0;🐍Wi-Fi: off | Done | 8.0.5soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
0;🐍Wi-Fi: off | main.py | 8.0.5
deactivate display..
toggle_led speed test running..
'toggle_led' needs 0.010ms/call
activate display..
'toggle_led ' needs 0.010ms/call
done...
0;🐍Wi-Fi: off | Done | 8.0.5
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
on my
Adafruit ESP32-S3 Reverse TFT Feather
(ESP32-S3 Dual Core 240MHz Tensilica processor)
0.01ms/call würde bei mir wohl so 100 MHz ergeben...
das erscheint mir schnell ;-)