
Async Python Is Not Faster — Here's When to Actually Use It
I see this mistake every week on Stack Overflow: "I rewrote my script with async and it got SLOWER. Why?" Because async Python is not about speed. It's about waiting efficiently . Let me explain with actual numbers. The Experiment Task: Make 100 HTTP requests to an API. Synchronous import httpx import time def sync_fetch ( urls ): results = [] for url in urls : r = httpx . get ( url , timeout = 10 ) results . append ( r . status_code ) return results urls = [ ' https://httpbin.org/delay/1 ' ] * 100 start = time . time () sync_fetch ( urls ) print ( f ' Sync: { time . time () - start : . 1 f } s ' ) # ~105 seconds Async import httpx import asyncio import time async def async_fetch ( urls ): async with httpx . AsyncClient () as client : tasks = [ client . get ( url , timeout = 10 ) for url in urls ] return await asyncio . gather ( * tasks ) start = time . time () asyncio . run ( async_fetch ( urls )) print ( f ' Async: { time . time () - start : . 1 f } s ' ) # ~2 seconds 105 seconds vs
Continue reading on Dev.to Tutorial
Opens in a new tab




