$ url = "https://httpbin.org"
$ %timeit r = requests.get(url)
119 ms ± 42.5 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
$ %timeit r = httpx.get(url)
%117 ms ± 17.6 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
$ http = urllib3.PoolManager()
$ %timeit response = http.request("GET", url)
The slowest run took 6.87 times longer than the fastest. This could mean that an intermediate result is being cached.
10.6 ms ± 6.91 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
其中还尝试了 session 等方法,貌似也没有变快,上面的是多次的测试,我还做了一次请求的测试,看上去也是很慢
看了看源码和原理,想象不出来这个速度差来自哪里?
需求就是请求网址需要快,但不一定需要多次请求