In a couple of youtube videos I’ve seen today, both David Beazley and Yuri S. say that async is 2x slower than functions. I don’t understand this. The whole point of async is concurrency, so even if a single function is faster than a single coroutine, that’s almost never going to be a real world situation. Instead, you’re going to have a lot of coroutines running at the same time, instead of one at a time with functions, so who cares if one on one a function is faster? How is that a relevant benchmark?
-
"The whole point of async is concurrency". As far as I understand the whole async-await stuff aka. PEP 492 -- Coroutines with async and await syntax is about coroutines as in pseudo multitasking and not concurrency as in multithreading so there is no parallelism speedup for running multiple coroutines and there will be overhead for coroutine management. The speedup comes from how coroutines are used and that won't be always better just because multiple coroutines are executed.makadev– makadev2016-10-15 00:47:22 +00:00Commented Oct 15, 2016 at 0:47
-
' speedup comes from how coroutines are used'. Is there a book, guide, best practices, etc that walks me through this? I don't find the word 'speed' anywhere in PEP 492.Malik A. Rumi– Malik A. Rumi2016-10-15 20:43:31 +00:00Commented Oct 15, 2016 at 20:43
-
I don't know any, personally I know about them from Computer Sience studies. There is some rather "fresh" information about coroutines with async. event loop - in python, ruby, c ... - on the www thought. F.e. this Chapter from 500 Lines or Less or David Beazleys Slides on Coroutines and Generators. Both only note on the side that letting coroutines work while others sleep - "waiting" on I/O - is sort of co-operative threadless multitasking. Speedup is implied.makadev– makadev2016-10-17 15:44:13 +00:00Commented Oct 17, 2016 at 15:44
Add a comment
|
1 Answer
Yes, a single await coro() call is two times slower than just func().
But the whole asyncio-based program in total may be (and often is) faster than threaded-based solution.
1 Comment
Malik A. Rumi
oh, ok. I had to read this a couple of times, and then it hit me: Since any given program can be of any length with any number of functions and or coroutines, there's be no way to benchmark a comparison unless you had two otherwise identical programs, one functions only and one coroutines only. It could be done, but I guess no one sees the need to do it?