1

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?

3
  • "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. Commented 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. Commented 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. Commented Oct 17, 2016 at 15:44

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.