python-trio / python-trio/trio

trio.timeit utility

Open
#677 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing Python's timeit API with the pytest-harness example in the issue, especially the perf_counter loop around trio.sleep(0). Check how an async utility would run inside a Trio context and what API compatibility is required. Done means the proposed utility measures fast async calls and has coverage for the sleep(0) use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.