tests/perf_bench: Add some viper performance benchmarks.

To test raw viper function call overhead: function entry, exit and
conversion of arguments to/from objects.
This commit is contained in:
Damien George 2019-06-26 14:27:32 +10:00
parent 73c269414f
commit 73fccf5967
6 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,19 @@
@micropython.viper
def f0():
pass
@micropython.native
def call(r):
f = f0
for _ in r:
f()
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)

View File

@ -0,0 +1,19 @@
@micropython.viper
def f1a(x):
return x
@micropython.native
def call(r):
f = f1a
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)

View File

@ -0,0 +1,19 @@
@micropython.viper
def f1b(x) -> int:
return int(x)
@micropython.native
def call(r):
f = f1b
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)

View File

@ -0,0 +1,19 @@
@micropython.viper
def f1c(x:int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)

View File

@ -0,0 +1,19 @@
@micropython.viper
def f2a(x, y):
return x
@micropython.native
def call(r):
f = f2a
for _ in r:
f(1, 2)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)

View File

@ -0,0 +1,19 @@
@micropython.viper
def f2b(x:int, y:int) -> int:
return x + y
@micropython.native
def call(r):
f = f2b
for _ in r:
f(1, 2)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)