pep-492: Update benchmark code
Since coroutines now have a distinct type, they do not support iteration. Instead of doing 'list(o)', we now do 'o.send(None)' until StopIteration. Note, that the updated timings are due to the difference of doing a loop in Python vs doing it in C ('list()' vs 'while True').
This commit is contained in:
parent
90da49bb4b
commit
0fb4b551a7
24
pep-0492.txt
24
pep-0492.txt
|
@ -1310,21 +1310,29 @@ difference between "async" functions and generators::
|
|||
r = await abinary(n - 1)
|
||||
return l + 1 + r
|
||||
|
||||
def timeit(gen, depth, repeat):
|
||||
def timeit(func, depth, repeat):
|
||||
t0 = time.time()
|
||||
for _ in range(repeat):
|
||||
list(gen(depth))
|
||||
o = func(depth)
|
||||
try:
|
||||
while True:
|
||||
o.send(None)
|
||||
except StopIteration:
|
||||
pass
|
||||
t1 = time.time()
|
||||
print('{}({}) * {}: total {:.3f}s'.format(
|
||||
gen.__name__, depth, repeat, t1-t0))
|
||||
func.__name__, depth, repeat, t1-t0))
|
||||
|
||||
The result is that there is no observable performance difference.
|
||||
Minimum timing of 3 runs
|
||||
The result is that there is no observable performance difference::
|
||||
|
||||
::
|
||||
binary(19) * 30: total 53.321s
|
||||
abinary(19) * 30: total 55.073s
|
||||
|
||||
abinary(19) * 30: total 12.985s
|
||||
binary(19) * 30: total 12.953s
|
||||
binary(19) * 30: total 53.361s
|
||||
abinary(19) * 30: total 51.360s
|
||||
|
||||
binary(19) * 30: total 49.438s
|
||||
abinary(19) * 30: total 51.047s
|
||||
|
||||
Note that depth of 19 means 1,048,575 calls.
|
||||
|
||||
|
|
Loading…
Reference in New Issue