Created
February 16, 2020 12:01
-
-
Save SirEdvin/878b2ffe50ed8e175aceb772bf2e6ef4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
51.83536124229431 | |
28.677456378936768 |
This file contains hidden or 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 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