1414# Busy loop: 127801 iterations/second
1515# Busy loop with yield: 38394 iterations/second
1616# SHA-256 (1KB): 5012 iterations/second
17+ #
18+ # New way, but now with 10 in a loop and 10 second tests for more stability:
19+ # Busy loop: 127000 iterations/second
20+ # Busy loop with yield: 46000 iterations/second => this went up 25%
21+ # SHA-256 (1KB): 5100 iterations/second
22+ #
23+ # Results on desktop:
24+ # Busy loop: 15 997 000 => 125x faster
25+ # Busy loop with yield: 10 575 000 => 229x faster
26+ # SHA-256 (1KB): 291 000 => 57x faster
27+
1728
1829import time
1930import hashlib
2536
2637# Configuration
2738START_SPACING = 2000 # Wait for system to settle
28- TEST_DURATION = 5000 # Duration of each test (ms)
39+ TEST_DURATION = 10000 # Duration of each test (ms)
2940TEST_SPACING = 1000 # Wait between tests (ms)
3041
3142def stress_test_thread ():
@@ -53,8 +64,9 @@ def stress_test_thread():
5364 start_time = time .ticks_ms ()
5465 end_time = start_time + TEST_DURATION
5566 while time .ticks_ms () < end_time and keeprunning :
56- iterations += 1
57- time .sleep_ms (0 ) # Yield to other tasks
67+ for _ in range (10 ):
68+ time .sleep_ms (0 ) # Yield to other tasks
69+ iterations += 10
5870 duration_ms = time .ticks_diff (time .ticks_ms (), start_time )
5971 iterations_per_second = (iterations / duration_ms ) * 1000
6072 print (f"Busy loop with yield test completed: { iterations_per_second :.2f} iterations/second" )
@@ -67,8 +79,9 @@ def stress_test_thread():
6779 start_time = time .ticks_ms ()
6880 end_time = start_time + TEST_DURATION
6981 while time .ticks_ms () < end_time and keeprunning :
70- hashlib .sha256 (DATA ).digest () # Compute SHA-256 on 1KB data
71- iterations += 1
82+ for _ in range (10 ):
83+ hashlib .sha256 (DATA ).digest () # Compute SHA-256 on 1KB data
84+ iterations += 10
7285 duration_ms = time .ticks_diff (time .ticks_ms (), start_time )
7386 iterations_per_second = (iterations / duration_ms ) * 1000
7487 print (f"SHA-256 test completed: { iterations_per_second :.2f} iterations/second" )
0 commit comments