Skip to content

Instantly share code, notes, and snippets.

@zsalzbank
Created March 2, 2015 22:53
Show Gist options
  • Select an option

  • Save zsalzbank/90ebcaaf94f6c34e9559 to your computer and use it in GitHub Desktop.

Select an option

Save zsalzbank/90ebcaaf94f6c34e9559 to your computer and use it in GitHub Desktop.
import time
import requests
headers = {}
url = 'https://sleepy-reaches-6892.herokuapp.com/test'
def test(timeout) :
start = time.time()
response = requests.get(url=url,
timeout=timeout, stream=True, headers=headers)
for x in response.iter_content(2) :
pass
print("T={}, stream iter took: {}".format(timeout, time.time() - start))
start = time.time()
response = requests.get(url=url,
timeout=timeout, stream=True)
response.content
print("T={}, stream all took: {}".format(timeout, time.time() - start))
start = time.time()
response = requests.get(url=url,
timeout=timeout, headers=headers)
response.content
print("T={}, no stream took: {}".format(timeout, time.time() - start))
test(10)
test(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment