NBNPC 最近的时间轴更新
NBNPC

NBNPC

V2EX 第 102446 号会员,加入于 2015-03-04 22:11:39 +08:00
今日活跃度排名 1460
NBNPC 最近回复了
49 天前
回复了 gzldc 创建的主题 Python 如何使用 Python 最快实现 1w 个 http 请求
python3.10 aiohttp 5000 次 本地 大概需要 10s

import asyncio
import time

import aiohttp


def timed(func):
async def wrapper():
start = time.time()
await func()
print(f"costs: {time.time() - start:.3f} S")

return wrapper


async def req(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return resp.status


@timed
async def main():
tasks = [req('http://httpbin.org/status/200') for _ in range(5000)]
result = await asyncio.gather(*tasks)
print(len(result), ' status: ', result[-1])
2020-12-28 21:03:15 +08:00
回复了 zhoudaiyu 创建的主题 Python Python 哪个 json 库反序列化最快?
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1008 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 23:52 · PVG 07:52 · LAX 16:52 · JFK 19:52
Developed with CodeLauncher
♥ Do have faith in what you're doing.