Skip to content

Instantly share code, notes, and snippets.

@SirEdvin
Created February 16, 2020 12:01
Show Gist options
  • Save SirEdvin/878b2ffe50ed8e175aceb772bf2e6ef4 to your computer and use it in GitHub Desktop.
Save SirEdvin/878b2ffe50ed8e175aceb772bf2e6ef4 to your computer and use it in GitHub Desktop.
51.83536124229431
28.677456378936768
import asyncio
import time
def fib(n):
if n == 1 or n == 0:
return 1
return fib(n - 1) + fib(n - 2)
async def verycomplexfunc():
for i in range(0, 15):
if i % 2 == 0:
await asyncio.sleep(1)
else:
fib(33)
async def sequence_call():
start_time = time.time()
await verycomplexfunc()
await verycomplexfunc()
await verycomplexfunc()
end_time = time.time()
return end_time - start_time
async def gather_call():
start_time = time.time()
await asyncio.gather(
verycomplexfunc(),
verycomplexfunc(),
verycomplexfunc(),
)
end_time = time.time()
return end_time - start_time
loop = asyncio.get_event_loop()
print(loop.run_until_complete(sequence_call()))
print(loop.run_until_complete(gather_call()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment