Files
zurg/bench.py
2023-11-28 21:38:48 +01:00

31 lines
836 B
Python

import aiohttp
import asyncio
from bs4 import BeautifulSoup
from urllib.parse import urljoin
import subprocess
async def extract_links(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
soup = BeautifulSoup(await response.text(), 'html.parser')
for link in soup.find_all('a'):
yield urljoin(url, link.get('href'))
async def benchmark(url):
# This will still block, because subprocess.run is not async
subprocess.run(['hey', '-n', '100', '-c', '10', url])
url = 'http://zen.box:9999/http/'
async def main():
i = 1
async for link in extract_links(url):
if i > 50:
break
await benchmark(link)
await benchmark(link.replace('/http/', '/'))
i += 1
# Python 3.7+
asyncio.run(main())