He is right for "yield from" syntax.
But there are more than enough zzwords.. ;)
"await" performs much better
and it is scalable for all async stack depths.
Change "if i==100" line for your stack depth.
Results (Relative to plain func call):
yield from:
110 (Stack Depth: 1)
210 (Stack Depth: 100)
await:
~2 (1 deep)
~2 (100 deep)
from asyncio import get_event_loop
from datetime import datetime
now = datetime.now
def foo1():
pass
def foo2():
yield
def layer(i=0):
if i == 100:
t = now()
for _ in range(10000):
yield from foo2()
tot2 = now() - t
print(tot2/tot1)
else:
yield from layer(i+1)
t1 = now()
for _ in range(10000):
foo1()
tot1 = now() - t1
loop = get_event_loop()
loop.run_until_complete(layer())
On 11/16/15, Victor Stinner <[email protected]> wrote:
> You may be interested by the blog post which is not really in favor of
> asyncio :-)
>
> http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/
>
> Victor
>
> 2015-11-12 18:16 GMT+01:00 Imran Geriskovan <[email protected]>:
>> What is the cost/overhead difference
>> between these calls?
>>
>> await foo1()
>> foo2()
>>
>> async def foo1():
>> pass
>>
>> def foo2():
>> pass
>>
>> Regards,
>> Imran
>