Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Trip coroutine demo
import time, functools
import requests, trip
def timeit(fn):
start_time = time.time()
return time.time() - start_time
url = ''
times = 10 # 100 changed for inland network delay
def fetch():
r = [requests.get(url) for i in range(times)]
return r
def async_fetch():
r = yield [trip.get(url) for i in range(times)]
raise trip.Return(r)
print('Non-trip cost: %ss' % timeit(fetch))
print('Trip cost: %ss' % timeit(functools.partial(, async_fetch)))
# Non-trip cost: 17.90799999237s
# Trip cost: 0.172300004959s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment