Created
May 7, 2012 20:48
-
-
Save piotr-dobrogost/2630312 to your computer and use it in GitHub Desktop.
This file contains 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 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