Skip to content

Commit 95f72a7

Browse files
committed
sdcard: Add read/write speed test to sdtest.
Writes and reads 1 MB through the FAT filesystem and prints throughput in KB/s. Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
1 parent d04161a commit 95f72a7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

micropython/drivers/storage/sdcard/sdtest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Peter hinch 30th Jan 2016
33
import machine
44
import os
5+
import time
56
import sdcard
67

78

@@ -44,6 +45,26 @@ def sdtest():
4445
result2 = f.read()
4546
print(len(result2), "bytes read")
4647

48+
fn = "/fc/speed.bin"
49+
buf = bytearray(32768) # 32 KB buffer
50+
51+
print()
52+
print("Write speed test")
53+
t = time.ticks_ms()
54+
with open(fn, "wb") as f:
55+
for _ in range(32): # 1 MB total
56+
f.write(buf)
57+
elapsed = time.ticks_diff(time.ticks_ms(), t)
58+
print("{} KB/s".format(32768 * 32 // elapsed))
59+
60+
print("Read speed test")
61+
t = time.ticks_ms()
62+
with open(fn, "rb") as f:
63+
while f.readinto(buf):
64+
pass
65+
elapsed = time.ticks_diff(time.ticks_ms(), t)
66+
print("{} KB/s".format(32768 * 32 // elapsed))
67+
4768
os.umount("/fc")
4869

4970
print()

0 commit comments

Comments
 (0)