I was just playing with the well known synthetic uPy benchmark:
Code: Select all
@micropython.viper
def performanceTest():
millis = pyb.millis
endTime = int(millis()) + 10000
count = 0
while int(millis()) < endTime:
count += 1
print("Count: ", count)
performanceTest()
Code: Select all
from pyb import millis
@micropython.viper
def performanceTest():
#millis = pyb.millis
endTime = int(millis()) + 10000
count = 0
while int(millis()) < endTime:
count += 1
print("Count: ", count)
performanceTest()
Code: Select all
@micropython.viper
def performanceTest():
#millis = pyb.millis
from pyb import millis
endTime = int(millis()) + 10000
count = 0
while int(millis()) < endTime:
count += 1
print("Count: ", count)
performanceTest()
I get the same behaviour when using @micropython.native or no decorator.
My current strategy is to put my imports on top of the file, since its more readable.
Is the conclusion that uPy is usually faster when placing the imports inside the function/method?
Btw: Tested on my STM32F4 Discovery (I own a pyboard, but borrowed it to my brother). Since the chip is the same it should show similar performance.