Sync with main
This commit is contained in:
30
bench.py
Normal file
30
bench.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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())
|
||||||
Reference in New Issue
Block a user