Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Created October 23, 2013 09:50
Show Gist options
  • Save elfenlaid/7115694 to your computer and use it in GitHub Desktop.
Save elfenlaid/7115694 to your computer and use it in GitHub Desktop.
Sync/async diff
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)
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
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