tests/perf_bench: Add perf test for yield-from execution.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-02-11 13:42:00 +11:00
parent 75da124cf8
commit a434705700
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
# Test a deep set of "yield from" statements.
def recursive_yield_from(depth, iter_):
if depth <= 0:
for i in iter_:
yield i
else:
yield from recursive_yield_from(depth - 1, iter_)
def test(n):
global result
result = 0
for i in recursive_yield_from(10, range(n)):
result += i
###########################################################################
# Benchmark interface
bm_params = {
(100, 10): (2000,),
(1000, 10): (20000,),
(5000, 10): (100000,),
}
def bm_setup(params):
(nloop,) = params
return lambda: test(nloop), lambda: (nloop // 100, result)