Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trio.timeit utility #677

Open
belm0 opened this issue Sep 22, 2018 · 0 comments
Open

trio.timeit utility #677

belm0 opened this issue Sep 22, 2018 · 0 comments

Comments

@belm0
Copy link
Member

belm0 commented Sep 22, 2018

Trio should offer an async timeit utility. It's useful for measuring performance of "fast" async calls such as sleep(0).

It's important for both trio devs and users to understand the overhead of checkpoints. E.g. for users: in situations where you're quickly draining an async queue, or when you're deciding how frequently to call sleep(0) in some CPU bound loop.

Here's an example using the pytest harness. Ideally we'd have a module with the same API as timeit, only running within a trio async context.

async def test_sleep0_perf():
    n = 10
    dt = 0
    while True:
        t0 = perf_counter()
        for _ in range(n):
            await trio.sleep(0)
        dt = perf_counter() - t0
        if dt < 0.2:
            n *= 10
        else:
            break
    print(f'{1e6 * dt / n: .1f} usec average in {n} calls')
    assert False
@belm0 belm0 changed the title trio_timeit utility trio.timeit utility Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants