Code: Select all
# test import
import pyb
from os import unlink, rename
from _io import StringIO, BytesIO
def imp_os():
from os import unlink, rename
return None
def imp_io():
from _io import StringIO, BytesIO
return None
start = pyb.millis()
for i in range(1000):
imp_os()
mid = pyb.millis()
for i in range(1000):
imp_io()
stop = pyb.millis()
print ("Import os: {} ms, import _io: {} ms".format((mid-start)/1000, (stop - mid)/1000))
>>> import imptest
Import os: 30.751 ms, import _io: 0.026 ms
It seems that the times differ by a factor of 1000, which I found surprising. if I load the full modules, the difference is even larger (31,5ms vs. 0,019ms)
MicroPython v1.5.1-171-g7ce8860 on 2015-12-25; PYBv1.0 with STM32F405RG
Update1: No substantial change with build MicroPython v1.5.1-190-g521759e on 2015-12-31; PYBv1.0 with STM32F405RG
Update2: If running from internal flash, the times are: Import os: 0.246 ms, import _io: 0.025 ms
Update 3: When loading uos instead of os, the times are similar: Import uos: 0.02 ms, import _io: 0.018 ms
Regards