Skip to content

Instantly share code, notes, and snippets.

@gsalgado
Created August 20, 2020 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsalgado/e8ce624054d4971fdf4342f62411313b to your computer and use it in GitHub Desktop.
Save gsalgado/e8ce624054d4971fdf4342f62411313b to your computer and use it in GitHub Desktop.
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())
@gsalgado
Copy link
Author

1k calls to noop(): 0.15616645599948242
1k run_in_executor() calls to noop(): 0.3189404949953314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment