Skip to content

Commit a6bdaff

Browse files
cputest: 3 threads
1 parent df7bb0e commit a6bdaff

File tree

1 file changed

+12
-22
lines changed
  • internal_filesystem/apps/com.example.cputest/assets

1 file changed

+12
-22
lines changed

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
def stress_test_busy_loop():
2626
print("\nStarting busy loop stress test...")
2727
global summary
28-
summary += "Busy loop without yield:"
29-
#status.set_text(summary)
28+
summary += "Busy loop without yield: "
3029
iterations = 0
3130
start_time = time.ticks_ms()
3231
end_time = start_time + TEST_DURATION
@@ -35,16 +34,14 @@ def stress_test_busy_loop():
3534
duration_ms = time.ticks_diff(time.ticks_ms(), start_time)
3635
iterations_per_second = (iterations / duration_ms) * 1000
3736
print(f"Busy loop test ran duration: {duration_ms}, average: {iterations_per_second:.2f} iterations/second")
38-
summary += f" {iterations_per_second:.2f}/s\n"
39-
#status.set_text(summary)
37+
summary += f"{iterations_per_second:.2f}/s\n"
4038
return iterations_per_second
4139

4240

4341
def stress_test_busy_loop_with_yield():
4442
print("\nStarting busy loop with yield (sleep_ms(0)) stress test...")
4543
global summary
46-
summary += "Busy loop with yield:"
47-
#status.set_text(summary)
44+
summary += "Busy loop with yield: "
4845
iterations = 0
4946
start_time = time.ticks_ms()
5047
end_time = start_time + TEST_DURATION
@@ -54,17 +51,13 @@ def stress_test_busy_loop_with_yield():
5451
duration_ms = time.ticks_diff(time.ticks_ms(), start_time)
5552
iterations_per_second = (iterations / duration_ms) * 1000
5653
print(f"Busy loop with yield test completed: {iterations_per_second:.2f} iterations/second")
57-
summary += f" {iterations_per_second:.2f}/s\n"
58-
#status.set_text(summary)
54+
summary += f"{iterations_per_second:.2f}/s\n"
5955
return iterations_per_second
6056

61-
def stress_test_busy_loop_with_yield_thread(timer):
62-
#_thread.stack_size(12*1024)
63-
_thread.start_new_thread(stress_test_busy_loop_with_yield, ())
64-
65-
def stress_test_sha256(timer):
57+
def stress_test_sha256():
6658
print("\nStarting SHA-256 stress test (1KB data)...")
67-
global status, summary
59+
global summary
60+
summary += "Busy loop with SHA-256 (1KB): "
6861
iterations = 0
6962
start_time = time.ticks_ms()
7063
end_time = start_time + TEST_DURATION
@@ -74,9 +67,8 @@ def stress_test_sha256(timer):
7467
duration_ms = time.ticks_diff(time.ticks_ms(), start_time)
7568
iterations_per_second = (iterations / duration_ms) * 1000
7669
print(f"SHA-256 test completed: {iterations_per_second:.2f} iterations/second")
77-
summary += f"SHA-256 (1KB): {iterations_per_second:.2f}/s\n"
70+
summary += f" {iterations_per_second:.2f}/s\n"
7871
summary += "\nAll tests completed."
79-
status.set_text(summary)
8072
return iterations_per_second
8173

8274

@@ -105,13 +97,11 @@ def janitor_cb(timer):
10597
_thread.stack_size(12*1024)
10698
_thread.start_new_thread(stress_test_busy_loop, ())
10799

108-
#stress_test_busy_loop_timer = lv.timer_create(stress_test_busy_loop, START_SPACING, None)
109-
#stress_test_busy_loop_timer.set_repeat_count(1)
110-
111-
stress_test_busy_loop_with_yield_timer = lv.timer_create(stress_test_busy_loop_with_yield_thread, TEST_DURATION * 2, None)
100+
stress_test_busy_loop_with_yield_timer = lv.timer_create(lambda timer: _thread.start_new_thread(stress_test_busy_loop_with_yield, ()), TEST_DURATION * 2, None)
112101
stress_test_busy_loop_with_yield_timer.set_repeat_count(1)
113102
stress_test_busy_loop_with_yield_timer.set_auto_delete(False)
114103

115-
#sha256_timer = lv.timer_create(stress_test_sha256, START_SPACING + 2 * TEST_DURATION + 2 * TEST_SPACING, None)
116-
#sha256_timer.set_repeat_count(1)
104+
stress_test_busy_loop_with_yield_timer = lv.timer_create(lambda timer: _thread.start_new_thread(stress_test_sha256, ()), TEST_DURATION * 4, None)
105+
stress_test_busy_loop_with_yield_timer.set_repeat_count(1)
106+
stress_test_busy_loop_with_yield_timer.set_auto_delete(False)
117107

0 commit comments

Comments
 (0)