Created
October 23, 2013 09:50
-
-
Save elfenlaid/7115694 to your computer and use it in GitHub Desktop.
Sync/async diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import grequests | |
urls = [ | |
'http://www.heroku.com', | |
'http://python-tablib.org', | |
'http://httpbin.org', | |
'http://python-requests.org', | |
'http://kennethreitz.com' | |
] | |
rs = (grequests.get(u) for u in urls) | |
print grequests.map(rs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elfenlaid$ time python sync_request.py | |
[200, 200, 200, 200, 200] | |
real 0m5.466s | |
user 0m0.187s | |
sys 0m0.046s | |
elfenlaid$ time python async_request.py | |
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>] | |
real 0m1.427s | |
user 0m0.184s | |
sys 0m0.045s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
urls = [ | |
'http://www.heroku.com', | |
'http://python-tablib.org', | |
'http://httpbin.org', | |
'http://python-requests.org', | |
'http://kennethreitz.com' | |
] | |
rs = (requests.get(u) for u in urls) | |
print map(lambda r: r.status_code, rs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment