Cookbook
Real-world patterns for using TimeRun: use metadata effectively, share results with your stack, time web traffic, and analyze timing data.
You already know the API from the Guide: timer overview, measure a block, measure function calls, metadata, and callbacks. Here we show how to apply it to concrete problems.
- Use metadata effectively — Add context (e.g. request id, stage) to every measurement by mutating metadata in
on_start. - Share results — Send measurements to logs, files, OpenTelemetry, or Prometheus using
on_end. - Time web requests — Wrap HTTP requests with
Timerin FastAPI, Flask, or Django. - Analyze results — Collect measurements and compute summaries or confidence intervals with standard tools.