Created
August 20, 2020 04:39
-
-
Save gsalgado/e8ce624054d4971fdf4342f62411313b 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
import asyncio | |
import time | |
def noop(): | |
time.sleep(0.0001) | |
async def f(): | |
start = time.monotonic() | |
for _ in range(1000): | |
noop() | |
end = time.monotonic() | |
print("1k calls to noop(): " + str(end - start)) | |
start = time.monotonic() | |
loop = asyncio.get_event_loop() | |
for _ in range(1000): | |
await loop.run_in_executor(None, noop) | |
end = time.monotonic() | |
print("1k run_in_executor() calls to noop(): " + str(end - start)) | |
asyncio.run(f()) |
Author
gsalgado
commented
Aug 20, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment