When I ran the code (see below) I demonstrated the expected improvement in execution speed from the .py module using the function decorators, but no improvement in performance using .mpy module built using the -X option.
This is the main.pyMicroPython v1.9.3 on 2017-11-01; PYBLITEv1.0 with STM32F411RE
Type "help()" for more information.
>>>
PYB: sync filesystems
PYB: soft reboot
Count: 1738251
Count native: 2739933
Count viper: 5333539
Count_C: 1731672
Count_C viper/int(millis()): 545414
Count_B: 1735226
Count_B viper/int(millis()): 545415
Code: Select all
import pyb
import performance_test as pt# .py file
import performance_testB as ptB#.mpy file with -X emit=viper
import performance_testC as ptC #mpy file without -X option
pt.performanceTest()
pt.performanceTest_native()
pt.performanceTest_viper()
ptC.performanceTest()
ptC.performanceTest_viper()
ptB.performanceTest()
ptB.performanceTest_viper()
Code: Select all
import pyb # this needs to be in the main for a .mpy file
def performanceTest():
millis = pyb.millis
endTime = millis() + 10000
count = 0
while millis() < endTime:
count += 1
print("Count_B: ", count)
#@micropython.viper
def performanceTest_viper():
millis = pyb.millis
endTime = int(millis()) + 10000
count = 0
while int(millis()) < endTime:
count += 1
print("Count_B viper/int(millis()): ", count)
def main():
performanceTest()
performanceTest_native()
performanceTest_viper()
if __name__ == "__main__":
main()
Code: Select all
import pyb
def performanceTest():
millis = pyb.millis
endTime = millis() + 10000
count = 0
while millis() < endTime:
count += 1
print("Count: ", count)
@micropython.native
def performanceTest_native():
millis = pyb.millis
endTime = millis() + 10000
count = 0
while millis() < endTime:
count += 1
print("Count native: ", count)
@micropython.viper
def performanceTest_viper():
millis = pyb.millis
endTime = int(millis()) + 10000
count = 0
while int(millis()) < endTime:
count += 1
print("Count viper: ", count)
def main():
performanceTest()
performanceTest_native()
performanceTest_viper()
if __name__ == "__main__":
main()