File write speed


New member
I've noticed that you can write data to the file system very quickly, about 1.3miliseconds per 8 byte block, but then every time 4096 bytes gets written it stalls for 90miliseconds.
The same effect happens on the ESP8266 but a little slower.
Is there a way to avoid this stalling? Can the async features get round this?
import time

fout = open("data2.txt", "w")
d = [ ]
t0 = time.ticks_ms()
n = 3000
sumdt = 0
i0 = 0
for i in range(n):
t = time.ticks_ms()
fout.write("%08d" % t)
dt = t-t0
if dt > 20:
d.append(((i-i0)*8, dt))
i0 = i
sumdt += dt
t0 = t
t = time.ticks_ms()
print("closetime", t-t0)
if i == n-1:
print("meanshortwrite", sumdt/(n-len(d)))
print("longwrite_ms", d)
meanshortwrite 1.314295
longwrite_ms [(8, 47), (4096, 88), (4096, 89), (4096, 88), (4096, 88), (4096, 89)]
Code not complete - assuming that File on an SD card?

SD cards do internal housekeeping in addition to file system overhead updates, occasional delays need to be expected to sometimes be over 100ms.

There are recent posts in recent days regarding SD timing.