Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: File write speed

  1. #1

    File write speed

    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?
    Code:
    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
    else:
    sumdt += dt
    t0 = t
    fout.close()
    t = time.ticks_ms()
    print("closetime", t-t0)
    if i == n-1:
    print("meanshortwrite", sumdt/(n-len(d)))
    print("longwrite_ms", d)
    result:
    meanshortwrite 1.314295
    longwrite_ms [(8, 47), (4096, 88), (4096, 89), (4096, 88), (4096, 88), (4096, 89)]

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,714
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •