Cookbook
Real-world recipes and production patterns for TimeRun: web frameworks, telemetry pipelines, AI/LLM token streaming, structured logging, and latency analysis.
Observability & Telemetry
- Share results — Push measurements to standard logging, JSONL files, OpenTelemetry traces, or Prometheus histograms in
on_end. - Structured logging with Structlog & Loguru — Emit structured JSON execution events with wall time, CPU time, and metadata.
- Use metadata effectively — Add contextual tags (e.g., request id, user id, experiment stage) to every measurement in
on_start.
Web & AI Applications
- Time web requests — Middleware patterns for FastAPI (Starlette), Flask, and Django to capture wall and CPU latency per HTTP request.
- Time LLM token streaming — Measure Time to First Token (TTFT) and total generation time across streaming AI/LLM responses.
Analysis & Performance
- Analyze results — Collect measurements to compute statistical summaries, confidence intervals, and percentiles (p50, p99) using NumPy and SciPy.
- Overhead & benchmarks — Verification of TimeRun's sub-microsecond overhead and patterns for micro-benchmarking algorithms.