前一段时间我们进行了
两种SDIO方式文件读取速度比较,站长就这个问题询问了ESP32_Lobo版的作者
Boris,他回答说是对于小文件两种方式区别不大。
为此,我们继续进行了大文件的读写测试。通过读取3个不同大小的文件,来判断读取速度。先将3个文件复制到SD卡,并改名为1、2、3,文件大小分别是:60708、639659、5235712。测试程序如下:
SD 1Line mode(4 Line mode程序类似,就不贴出了)
- import os
- import time
- os.sdconfig(os.SDMODE_1LINE)
- os.mountsd()
- def filesize(fn):
- try:
- i = os.stat(fn)
- return i[6]
- except:
- return 0
- def loadf(p):
- total = 0
- print('============================================')
- print('file name:', p[0])
- print('file size:', filesize(p[0]))
- for i in range(p[1]):
- with open(p[0]) as f:
- while True:
- x = len(f.read(1024))
- total += x
- if x<1024:
- break
- return total
- def time_it(f, n):
- t0 = time.ticks_us()
- total = f(n)
- t1 = time.ticks_us()
- dt = time.ticks_diff(t1, t0)
- print('{} bytes {:5.3f} sec : {:8.3f} Mbytes/sec'.format(total, dt * 1e-6, total/dt))
- return total/dt
- print('============================================')
- print(' ESP32 SD 1Line mode speed test:')
- r0 = time_it(loadf, ('/sd/0', 10))
- r1 = time_it(loadf, ('/sd/1', 1))
- r2 = time_it(loadf, ('/sd/2', 1))
复制代码
测试结果
SD 1Line mode
- ============================================
- ESP32 SD 1Line mode speed test:
- ============================================
- file name: /sd/0
- file size: 60708
- 459910 bytes 2.111 sec : 0.218 Mbytes/sec
- ============================================
- file name: /sd/1
- file size: 639659
- 639659 bytes 4.029 sec : 0.159 Mbytes/sec
- ============================================
- file name: /sd/2
- file size: 5235712
- 5167548 bytes 29.547 sec : 0.175 Mbytes/sec
- >>>
复制代码
SD 4Line mode
- ============================================
- ESP32 SD 4Line mode speed test:
- ============================================
- file name: /sd/0
- file size: 60708
- 459910 bytes 2.027 sec : 0.227 Mbytes/sec
- ============================================
- file name: /sd/1
- file size: 639659
- 639659 bytes 3.967 sec : 0.161 Mbytes/sec
- ============================================
- file name: /sd/2
- file size: 5235712
- 5167548 bytes 28.836 sec : 0.179 Mbytes/sec
- >>>
复制代码
可以看到,1Line和4Line模式的结果仍然差别非常小。
此内容由EEWORLD论坛网友dcexpert原创,如需转载或用于商业用途需征得作者同意并注明出处