mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 18:02:04 +03:00
Replaced sequential HTTP POST requests with `asyncio.gather` for the Cloudflare upload speed test in `tier_cloudflare`. This allows payloads to be uploaded concurrently, significantly improving the upload throughput measurement (observed increase from ~15 Mbps to ~33 Mbps in benchmarks) and reducing total test duration. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
21 lines
684 B
Python
21 lines
684 B
Python
import asyncio
|
|
import httpx
|
|
import time
|
|
from netsleuth.config import Speedtest
|
|
from netsleuth.speed import tier_cloudflare, throughput_from_samples
|
|
|
|
async def main():
|
|
cfg = Speedtest(
|
|
download_sizes_bytes=[],
|
|
upload_sizes_bytes=[100000, 200000, 500000, 1000000, 2000000],
|
|
cloudflare_base_url="https://speed.cloudflare.com",
|
|
)
|
|
async with httpx.AsyncClient() as client:
|
|
began = time.perf_counter()
|
|
res = await tier_cloudflare(client, cfg, 30.0)
|
|
elapsed = time.perf_counter() - began
|
|
print(f"Elapsed: {elapsed:.3f}s")
|
|
print(f"Upload mbps: {res.upload_mbps}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|