Skip to content

Commit 464d1bb

Browse files
cputest: optimize
1 parent fc9a4bc commit 464d1bb

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

internal_filesystem/apps/com.example.cputest/assets/cputest.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# Busy loop: 22289 iterations/second
1010
# Busy loop with yield: 15923 iterations/second
1111
# SHA-256 (1KB): 5269 iterations/second
12+
#
13+
# New way, with the tests in a thread, replacing appscreen == lv.screen_active() with keeprunning:
14+
# Busy loop: 127801 iterations/second
15+
# Busy loop with yield: 38394 iterations/second
16+
# SHA-256 (1KB): 5012 iterations/second
1217

1318
import time
1419
import hashlib
@@ -19,14 +24,17 @@
1924
summary = "Running 3 CPU tests...\n\n"
2025

2126
# Configuration
27+
START_SPACING = 2000 # Wait for system to settle
2228
TEST_DURATION = 5000 # Duration of each test (ms)
2329
TEST_SPACING = 1000 # Wait between tests (ms)
24-
DATA_SIZE = 1024 # 1KB of data for SHA-256 test
25-
DATA = os.urandom(DATA_SIZE) # Generate 1KB of random data for SHA-256
2630

2731
def stress_test_thread():
28-
print("\nStarting busy loop stress test...")
32+
DATA_SIZE = 1024 # 1KB of data for SHA-256 test
33+
DATA = os.urandom(DATA_SIZE) # Generate 1KB of random data for SHA-256
34+
print("stress_test_thread running")
2935
global summary, keeprunning
36+
summary += "Waiting for system to settle...\n\n"
37+
time.sleep_ms(START_SPACING)
3038
summary += "Busy loop without yield: "
3139
iterations = 0
3240
start_time = time.ticks_ms()
@@ -77,8 +85,8 @@ def janitor_cb(timer):
7785
update_status_timer.delete()
7886

7987
appscreen = lv.screen_active()
80-
janitor = lv.timer_create(janitor_cb, 500, None)
81-
update_status_timer = lv.timer_create(lambda timer: status.set_text(summary), 200, None)
88+
janitor = lv.timer_create(janitor_cb, 1000, None)
89+
update_status_timer = lv.timer_create(lambda timer: status.set_text(summary), 750, None)
8290

8391
status = lv.label(appscreen)
8492
status.align(lv.ALIGN.TOP_LEFT, 5, 10)

internal_filesystem/apps/com.example.helloworld/assets/hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# END OF COPY-PASTE FROM https://sim.lvgl.io/v9.0/micropython/ports/webassembly/
1818

19-
19+
# Optional janitor that cleans up when the app is backgrounded:
2020
def janitor_cb(timer):
2121
if lv.screen_active() != scr:
2222
print("app backgrounded, cleaning up...")

internal_filesystem/lib/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ This /lib folder contains:
77

88
- maybe mip.install("aiohttp") # easy websockets
99
- maybe mip.install("base64") # for nostr etc
10+
- mip.install("urequests") # otherwise not present on unix target (on esp32 it is present)
11+

0 commit comments

Comments
 (0)