python grequests和requests比较

mac2022-06-30  24

#!/usr/bin/env python # encoding: utf-8 import grequests import requests import timeit import time def greq(): urls = [ 'http://www.heroku.com', 'http://python-tablib.org', 'http://httpbin.org', 'http://python-requests.org', 'http://fakedomain/', 'http://kennethreitz.com' ] rs = (grequests.get(u) for u in urls) start=time.time() for i in grequests.map(rs): pass #print(i) def req(): urls = [ 'http://www.heroku.com', 'http://python-tablib.org', 'http://httpbin.org', 'http://python-requests.org', 'http://fakedomain/', 'http://kennethreitz.com' ] for i in urls: response=requests.get(i) #print(response) print("user-grequests",timeit.timeit(stmt=greq,number=1)) print("user-requests",timeit.timeit(stmt=req,number=1))

  

转载于:https://www.cnblogs.com/c-x-a/p/9006656.html

相关资源:Python-GRequests简化HTTP异步请求
最新回复(0)