Skip to content

Commit 72fed78

Browse files
authored
chore: add benchmark to create and destroy an instance (#1317)
1 parent 1b5cc24 commit 72fed78

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

bench/create_destory.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Benchmark for AsyncZeroconf."""
2+
import asyncio
3+
import time
4+
5+
from zeroconf.asyncio import AsyncZeroconf
6+
7+
iterations = 10000
8+
9+
10+
async def _create_destroy(count: int) -> None:
11+
for _ in range(count):
12+
async with AsyncZeroconf() as zc:
13+
await zc.zeroconf.async_wait_for_start()
14+
15+
16+
async def _run() -> None:
17+
start = time.perf_counter()
18+
await _create_destroy(iterations)
19+
duration = time.perf_counter() - start
20+
print(f"Creating and destroying {iterations} Zeroconf instances took {duration} seconds")
21+
22+
23+
asyncio.run(_run())

0 commit comments

Comments
 (0)