I am almost sure that the differences we see are related to the Python dynamic memory management. I ran another test which was provided a while ago by @pythoncoder, which just does arithmetic and a little bit of looping. There, the numbers are consistent over all versions. That matches my observation when using the port, that there is no noticeable difference over the various versions. Peter's test script:
Code: Select all
import time
import machine
def pi(places=100):
# 3 + 3*(1/24) + 3*(1/24)*(9/80) + 3*(1/24)*(9/80)*(25/168)
# The numerators 1, 9, 25, ... are given by (2x + 1) ^ 2
# The denominators 24, 80, 168 are given by (16x^2 -24x + 8)
extra = 8
one = 10 ** (places+extra)
t, c, n, na, d, da = 3*one, 3*one, 1, 0, 0, 24
while t > 1:
n, na, d, da = n+na, na+8, d+da, da+32
t = t * n // d
c += t
return c // (10 ** extra)
def pi_test(n=5000):
t1=time.ticks_ms()
t=pi(n)
t2=time.ticks_ms()
print('Pi test: ', time.ticks_diff(t2,t1)/1000, 's')
def pass_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
pass
t2=time.ticks_ms()
print('Pass test: ', time.ticks_diff(t2,t1)/1000, 's')
@micropython.native
def passn_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
pass
t2=time.ticks_ms()
print('Pass test native: ', time.ticks_diff(t2,t1)/1000, 's')
def add_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
sum = a + b
t2=time.ticks_ms()
print('Add test: ', time.ticks_diff(t2,t1)/1000, 's')
@micropython.native
def addn_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
sum = a + b
t2=time.ticks_ms()
print('Add test native: ', time.ticks_diff(t2,t1)/1000, 's')
def mul_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
sum = a * b
t2=time.ticks_ms()
print('Mul test: ', time.ticks_diff(t2,t1)/1000, 's')
def div_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
sum = a / b
t2=time.ticks_ms()
print('Div test: ', time.ticks_diff(t2,t1)/1000, 's')
def idiv_test(n=1000000, a = 1234, b = 5678):
t1=time.ticks_ms()
sum = 0
for i in range(n):
sum = b // a
t2=time.ticks_ms()
print('iDiv test: ', time.ticks_diff(t2,t1)/1000, 's')
print('Speed test')
try:
print('System freq: {:.1f} MHz'.format(machine.freq()[0]/1000000))
except:
print('System freq: {:.1f} MHz'.format(machine.freq()/1000000))
pass_test()
passn_test()
add_test()
add_test(1000000, 1234.1, 5678.1)
addn_test()
addn_test(1000000, 1234.1, 5678.1)
mul_test()
mul_test(1000000, 1234.1, 5678.1)
div_test()
div_test(1000000, 5678.1, 1234.1)
idiv_test()
pi_test()
Note: For versions before 1..15-183 you have to comment the decorator. Support for that came with 1.15-183.
And some results:
Code: Select all
MicroPython v1.16-19-g8b1d75b8d on 2021-06-23
System freq: 600.0 MHz
Pass test: 0.443 s
Pass test native: 0.215 s
Add test: 0.641 s
Add test: 1.367 s
Add test native: 0.277 s
Add test native: 1.219 s
Mul test: 0.693 s
Mul test: 1.377 s
Div test: 1.369 s
Div test: 1.443 s
iDiv test: 0.677 s
Pi test: 2.211 s
MicroPython v1.15-182-ga40e1473d on 2021-06-23
System freq: 0.0 MHz
Pass test: 0.447 s
Add test: 0.64 s
Add test: 1.363 s
Mul test: 0.697 s
Mul test: 1.373 s
Div test: 1.189 s
Div test: 1.439 s
iDiv test: 0.675 s
Pi test: 2.017 s
MicroPython v1.15-183-gbbdc98f72 on 2021-06-23
System freq: 600.0 MHz
Pass test: 0.447 s
Pass test native: 0.221 s
Add test: 0.64 s
Add test: 1.366 s
Add test native: 0.286 s
Add test native: 0.907 s
Mul test: 0.697 s
Mul test: 1.384 s
Div test: 1.201 s
Div test: 1.447 s
iDiv test: 0.675 s
Pi test: 2.124 s
Some earlier results with ESP32 and PybD-SF6
Code: Select all
Runtest, ESP32 with spiram
Speed test
System freq: 240.0 MHz
Add test: 3.514 s
Mul test: 3.703 s
Div test: 7.758 s
Pi test: 16.149 s
Runtest, ESP32 without spiram, firmware with spiram support
Speed test
System freq: 240.0 MHz
Add test: 3.225 s
Mul test: 3.418 s
Div test: 4.599 s
Pi test: 11.29 s
Runtest, ESP32 without spiram, firmware without spiram support
Speed test
System freq: 240.0 MHz
Add test: 3.064 s
Mul test: 3.255 s
Div test: 4.368 s
Pi test: 9.005 s
MicroPython v1.9.4-793-gaba83e66-dirty on 2019-02-05; ESP32 module with ESP32
Runtest, ESP32 without spiram, firmware without spiram support
Speed test
System freq: 240.0 MHz
Add test: 2.625 s
Mul test: 2.809 s
Div test: 15.874 s
Pi test: 8.354 s
PyBoard D SF6.
MicroPython v1.16-13-gc99e4995f on 2021-06-23
Speed test
System freq: 192.0 MHz
Pass test: 1.089 s
Pass test native: 0.6680000000000001 s
Add test: 1.704 s
Add test: 4.248 s
Add test native: 0.893 s
Add test native: 2.933 s
Mul test: 1.881 s
Mul test: 4.258 s
Div test: 3.562 s
Div test: 4.46 s
iDiv test: 1.818 s
Pi test: 7.073 s
: