Last active
November 30, 2021 18:54
-
-
Save yezz123/c3323c1f5787d4f151b40856da0868b9 to your computer and use it in GitHub Desktop.
GDG Casablanca 2021 - Demo
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 time | |
import asyncio | |
t1 = time.time() | |
async def loop(arg, name): | |
track = 1 | |
print(name, "Started at", time.time() - t1) | |
for i in range(arg): | |
if i == track * 1000: | |
await asyncio.sleep(0.25) | |
track += 1 | |
print("Finished", name, "at", time.time() - t1) | |
async def main(): | |
await asyncio.gather( | |
loop(50_000, "COROUTINE 1"), loop(10_000, "COROUTINE 2")) | |
print("Finished in", time.time() - t1, "secs") | |
asyncio.run(main()) |
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 asyncio | |
import time | |
t1 = time.time() | |
async def fetch_posts(arg): | |
await asyncio.sleep(arg) | |
print("Fetched all posts") | |
async def fetch_users(arg): | |
await asyncio.sleep(arg) | |
print("Fetched all Users") | |
async def main(): | |
await asyncio.gather(fetch_posts(2), fetch_users(1) | |
) | |
print("Finished in", time.time() - t1, "secs") | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
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 time | |
t1 = time.time() | |
def fetch_posts(arg): | |
time.sleep(arg) | |
print("Fetched all posts") | |
def fetch_users(arg): | |
time.sleep(arg) | |
print("Fetched all Users") | |
def main(): | |
fetch_posts(2) | |
fetch_users(1) | |
print("Finished in", time.time() - t1, "secs") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment