You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Simplify
This commit is contained in:
@@ -32,6 +32,8 @@ import time
|
||||
# Configuration
|
||||
ALLOCATION_TIMEOUT_MS = 100 # Timeout for a single allocation (in milliseconds)
|
||||
|
||||
|
||||
|
||||
def test_allocation(buffer_size, n):
|
||||
"""Test how many buffers of a given size can be allocated with a timeout."""
|
||||
print(f"\nTesting buffer size: {buffer_size} bytes (2^{n})")
|
||||
@@ -66,46 +68,40 @@ def test_allocation(buffer_size, n):
|
||||
gc.collect()
|
||||
return count
|
||||
|
||||
def main():
|
||||
print("Starting memory allocation test...")
|
||||
|
||||
# Store results for summary
|
||||
results = []
|
||||
|
||||
# Test buffer sizes of 2^n, starting from n=1 (2 bytes)
|
||||
n = 1
|
||||
while True:
|
||||
buffer_size = 2 ** n
|
||||
# Run allocation test
|
||||
max_buffers = test_allocation(buffer_size, n)
|
||||
results.append((buffer_size, max_buffers))
|
||||
|
||||
# Check if we allocated 0 buffers (indicates we can't allocate this size)
|
||||
if max_buffers == 0:
|
||||
print(f"Cannot allocate buffers of size {buffer_size} bytes. Stopping test.")
|
||||
break
|
||||
|
||||
# Clean up memory before next test
|
||||
gc.collect()
|
||||
time.sleep_ms(100) # Brief delay to stabilize system
|
||||
|
||||
n += 1
|
||||
|
||||
# Print summary report
|
||||
print("\n=== Memory Allocation Test Summary ===")
|
||||
print("Buffer Size (bytes) | Max Buffers Allocated")
|
||||
print("-" * 40)
|
||||
for buffer_size, max_buffers in results:
|
||||
print(f"{buffer_size:>18} | {max_buffers:>20}")
|
||||
print("=====================================")
|
||||
print("Test completed.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# Run garbage collection before starting to ensure clean state
|
||||
gc.collect()
|
||||
main()
|
||||
except Exception as e:
|
||||
print(f"Error during test: {e}")
|
||||
print("Starting memory allocation test...")
|
||||
|
||||
# Store results for summary
|
||||
results = []
|
||||
|
||||
# Test buffer sizes of 2^n, starting from n=1 (2 bytes)
|
||||
n = 1
|
||||
|
||||
canary = lv.obj(subwindow)
|
||||
canary.add_flag(0x0001) # LV_OBJ_FLAG_HIDDEN is 0x0001
|
||||
|
||||
while canary.get_class():
|
||||
buffer_size = 2 ** n
|
||||
# Run allocation test
|
||||
gc.collect()
|
||||
max_buffers = test_allocation(buffer_size, n)
|
||||
results.append((buffer_size, max_buffers))
|
||||
# Check if we allocated 0 buffers (indicates we can't allocate this size)
|
||||
if max_buffers == 0:
|
||||
print(f"Cannot allocate buffers of size {buffer_size} bytes. Stopping test.")
|
||||
break
|
||||
# Clean up memory before next test
|
||||
gc.collect()
|
||||
time.sleep_ms(100) # Brief delay to stabilize system
|
||||
n += 1
|
||||
|
||||
|
||||
# Print summary report
|
||||
print("\n=== Memory Allocation Test Summary ===")
|
||||
print("Buffer Size (bytes) | Max Buffers Allocated")
|
||||
print("-" * 40)
|
||||
for buffer_size, max_buffers in results:
|
||||
print(f"{buffer_size:>18} | {max_buffers:>20}")
|
||||
print("=====================================")
|
||||
print("Test completed.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user