timing.py
python
sha256:b636f72dcba9e190afb980bece906fa5b717fbde014b76ef023df8cb96e01eb9
docs: expand cache plan with all seven testing tiers and do…
Sonnet 4.6
132 days ago
| 1 | """Monotonic timing utility for agent-facing JSON output. |
| 2 | |
| 3 | Every ``muse`` command that emits JSON includes ``duration_ms`` and |
| 4 | ``exit_code`` so agents can measure latency and check results without |
| 5 | inspecting the process exit status separately. |
| 6 | |
| 7 | Usage:: |
| 8 | |
| 9 | |
| 10 | elapsed = start_timer() |
| 11 | # ... do work ... |
| 12 | output["duration_ms"] = elapsed() |
| 13 | output["exit_code"] = 0 |
| 14 | """ |
| 15 | |
| 16 | from __future__ import annotations |
| 17 | |
| 18 | import time |
| 19 | from collections.abc import Callable |
| 20 | |
| 21 | |
| 22 | def start_timer() -> Callable[[], float]: |
| 23 | """Capture a monotonic start time and return an elapsed-ms callable. |
| 24 | |
| 25 | Returns: |
| 26 | A zero-argument callable that, when called, returns the number of |
| 27 | milliseconds elapsed since ``start_timer()`` was called, rounded |
| 28 | to three decimal places. |
| 29 | |
| 30 | Example:: |
| 31 | |
| 32 | elapsed = start_timer() |
| 33 | do_work() |
| 34 | ms = elapsed() # e.g. 12.345 |
| 35 | """ |
| 36 | t0 = time.monotonic() |
| 37 | return lambda: round((time.monotonic() - t0) * 1000, 3) |
File History
2 commits
sha256:b636f72dcba9e190afb980bece906fa5b717fbde014b76ef023df8cb96e01eb9
docs: expand cache plan with all seven testing tiers and do…
Sonnet 4.6
132 days ago
sha256:7f9e2ef5286aedad9c1e6011b4c46ca27f39dbdad6e3409357e36b26e46b3b7c
docs: docstring sprint for-each-ref→hotspots — idiomatic ru…
Sonnet 4.6
patch
138 days ago