Malik A. Rumi
Malik A. Rumi

Reputation: 2035

python async speed compared to functions

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?

Upvotes: 1

Views: 585

Answers (1)

Andrew Svetlov
Andrew Svetlov

Reputation: 17376

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.

Upvotes: 3

Related Questions