Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Created June 1, 2018 04:37
Show Gist options
  • Save pfreixes/18f0c678a9a018be0f376d4bef6d722a to your computer and use it in GitHub Desktop.
Save pfreixes/18f0c678a9a018be0f376d4bef6d722a to your computer and use it in GitHub Desktop.
Getting the figures of how much overhead implies having a Collector installed
import asyncio
import contextvars
import uvloop
from types import SimpleNamespace
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
N = 100000
class TaskCollector(uvloop.TracingCollector):
## Collector methods
def task_created(self, task):
pass
async def foo():
return
async def main(loop):
with uvloop.tracing(TaskCollector()):
start = loop.time()
for i in range(N):
task = loop.create_task(foo())
delta = loop.time() - start
return delta
loop = asyncio.get_event_loop()
deltas = [loop.run_until_complete(main(loop)) for i in range(5)]
delta = min(deltas)
print(f"No tracing: Cost per {N} task {delta}, per task {delta/N}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment