Created
February 23, 2017 21:30
-
-
Save nenodias/d3a234a8357b589764d7160662f14488 to your computer and use it in GitHub Desktop.
Async IO
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 | |
| from time import time | |
| def run_async(): | |
| startT = time() | |
| async def speak_async(): | |
| print("With Async :)") | |
| loop = asyncio.get_event_loop() | |
| loop.run_until_complete(speak_async()) | |
| loop.close() | |
| print(time() - startT) | |
| def run_sync(): | |
| startT = time() | |
| def speak(): | |
| print("Withou Async :(") | |
| speak() | |
| print(time() - startT) | |
| if __name__ == '__main__': | |
| valor = None | |
| while valor != '1' and valor != '2': | |
| valor = input('Executar: (1 - Async | 2 - Sync)') | |
| if valor == '1': | |
| run_async() | |
| elif valor == '2': | |
| run_sync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment