@@ -346,3 +346,131 @@ async def run_client_benchmark() -> None:
346346 @benchmark
347347 def _run () -> None :
348348 loop .run_until_complete (run_client_benchmark ())
349+
350+
351+ def test_ten_streamed_responses_iter_any (
352+ loop : asyncio .AbstractEventLoop ,
353+ aiohttp_client : AiohttpClient ,
354+ benchmark : BenchmarkFixture ,
355+ ) -> None :
356+ """Benchmark 10 streamed responses using iter_any."""
357+ message_count = 10
358+ data = b"x" * 65536 # 64 KiB chunk size
359+
360+ async def handler (request : web .Request ) -> web .StreamResponse :
361+ resp = web .StreamResponse ()
362+ await resp .prepare (request )
363+ for _ in range (10 ):
364+ await resp .write (data )
365+ return resp
366+
367+ app = web .Application ()
368+ app .router .add_route ("GET" , "/" , handler )
369+
370+ async def run_client_benchmark () -> None :
371+ client = await aiohttp_client (app )
372+ for _ in range (message_count ):
373+ resp = await client .get ("/" )
374+ async for _ in resp .content .iter_any ():
375+ pass
376+ await client .close ()
377+
378+ @benchmark
379+ def _run () -> None :
380+ loop .run_until_complete (run_client_benchmark ())
381+
382+
383+ def test_ten_streamed_responses_iter_chunked_4096 (
384+ loop : asyncio .AbstractEventLoop ,
385+ aiohttp_client : AiohttpClient ,
386+ benchmark : BenchmarkFixture ,
387+ ) -> None :
388+ """Benchmark 10 streamed responses using iter_chunked 4096."""
389+ message_count = 10
390+ data = b"x" * 65536 # 64 KiB chunk size, 4096 iter_chunked
391+
392+ async def handler (request : web .Request ) -> web .StreamResponse :
393+ resp = web .StreamResponse ()
394+ await resp .prepare (request )
395+ for _ in range (10 ):
396+ await resp .write (data )
397+ return resp
398+
399+ app = web .Application ()
400+ app .router .add_route ("GET" , "/" , handler )
401+
402+ async def run_client_benchmark () -> None :
403+ client = await aiohttp_client (app )
404+ for _ in range (message_count ):
405+ resp = await client .get ("/" )
406+ async for _ in resp .content .iter_chunked (4096 ):
407+ pass
408+ await client .close ()
409+
410+ @benchmark
411+ def _run () -> None :
412+ loop .run_until_complete (run_client_benchmark ())
413+
414+
415+ def test_ten_streamed_responses_iter_chunked_65536 (
416+ loop : asyncio .AbstractEventLoop ,
417+ aiohttp_client : AiohttpClient ,
418+ benchmark : BenchmarkFixture ,
419+ ) -> None :
420+ """Benchmark 10 streamed responses using iter_chunked 65536."""
421+ message_count = 10
422+ data = b"x" * 65536 # 64 KiB chunk size, 64 KiB iter_chunked
423+
424+ async def handler (request : web .Request ) -> web .StreamResponse :
425+ resp = web .StreamResponse ()
426+ await resp .prepare (request )
427+ for _ in range (10 ):
428+ await resp .write (data )
429+ return resp
430+
431+ app = web .Application ()
432+ app .router .add_route ("GET" , "/" , handler )
433+
434+ async def run_client_benchmark () -> None :
435+ client = await aiohttp_client (app )
436+ for _ in range (message_count ):
437+ resp = await client .get ("/" )
438+ async for _ in resp .content .iter_chunked (65536 ):
439+ pass
440+ await client .close ()
441+
442+ @benchmark
443+ def _run () -> None :
444+ loop .run_until_complete (run_client_benchmark ())
445+
446+
447+ def test_ten_streamed_responses_iter_chunks (
448+ loop : asyncio .AbstractEventLoop ,
449+ aiohttp_client : AiohttpClient ,
450+ benchmark : BenchmarkFixture ,
451+ ) -> None :
452+ """Benchmark 10 streamed responses using iter_chunks."""
453+ message_count = 10
454+ data = b"x" * 65536 # 64 KiB chunk size
455+
456+ async def handler (request : web .Request ) -> web .StreamResponse :
457+ resp = web .StreamResponse ()
458+ await resp .prepare (request )
459+ for _ in range (10 ):
460+ await resp .write (data )
461+ return resp
462+
463+ app = web .Application ()
464+ app .router .add_route ("GET" , "/" , handler )
465+
466+ async def run_client_benchmark () -> None :
467+ client = await aiohttp_client (app )
468+ for _ in range (message_count ):
469+ resp = await client .get ("/" )
470+ async for _ in resp .content .iter_chunks ():
471+ pass
472+ await client .close ()
473+
474+ @benchmark
475+ def _run () -> None :
476+ loop .run_until_complete (run_client_benchmark ())
0 commit comments