Skip to content

Instantly share code, notes, and snippets.

@piotr-dobrogost
Created May 7, 2012 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotr-dobrogost/2630312 to your computer and use it in GitHub Desktop.
Save piotr-dobrogost/2630312 to your computer and use it in GitHub Desktop.
import sys
from requests import request
from requests import async
URL = 'http://httpbin.org/get'
def get():
return request('get', URL)
def async_get():
req = async.request('get', URL)
return async.map([req])[0]
if __name__ == '__main__':
all = 50
for get, mode in ((get, 'SYNC'), (async_get, 'ASYNC')):
failed = 0
exceptions = 0
for run in xrange(all):
try:
res = get()
if res:
print '.',
else:
print '*',
failed += 1
except Exception:
print 'x',
exceptions +=1
print '\n%s http errors: %f%%, exceptions %f%%' % (mode,
(float(failed)/all)*100,
(float(exceptions)/all)*100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment