Created
June 1, 2018 04:37
-
-
Save pfreixes/18f0c678a9a018be0f376d4bef6d722a to your computer and use it in GitHub Desktop.
Getting the figures of how much overhead implies having a Collector installed
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 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