tprof 1.3.0 is released with major performance improvements for this Python 3.12+ targeting profiler. Key changes include replacing Python data structures with per-thread C structures storing raw int64_t nanosecond values, disabling sys.monitoring callbacks entirely for non-target code, and using PyTime_PerfCounterRaw() on Python 3.13+. Benchmarks show target function overhead reduced ~3×, non-target functions now run at full speed (zero overhead), memory use is 4× lower, and report generation is ~100× faster. New features include --json/--baseline flags for cross-branch performance comparisons, median replacing mean as the headline statistic (computed via quickselect in C), and programmatic access to results via FunctionStats objects yielded from the tprof() context manager/decorator.

4m read timeFrom adamj.eu
Post cover image
Table of contents
Way less overheadComparing against a saved baselineMedian, not meanProgrammatic access to resultsFin

Questions this post answers

How much overhead does tprof add to profiled functions in Python 3.13?

In tprof 1.3.0 on Python 3.13, a target function call takes about 170ns (+141ns overhead vs. unprofiled), down from 469ns (+439ns) in previous versions — roughly a 3× reduction. Non-target functions now run at full speed with zero added overhead (28ns, +0), compared to 440ns (+410ns) before. Memory per 1M calls dropped from 34.8 MiB to 8.0 MiB, and report generation went from ~430ms to ~3ms. Python developers benchmarking profiler overhead track tprof releases and similar tooling on daily.dev.

How do I compare tprof results across two Git branches in Python?

Use tprof's --json flag to save results from one branch, then pass that file to --baseline on the other branch. Run `tprof -t lib:maths --json before.json ./example.py` on the baseline branch, then after checking out your change run `tprof -t lib:maths --baseline before.json ./example.py`. The report adds a delta column showing each function's median change as a percentage. Teams optimizing Python code across branches find workflow tips like this on daily.dev.

How do I access tprof profiling results programmatically in Python instead of just reading the printed report?

The tprof() context manager and decorator now yield a list of FunctionStats objects once the profiled block ends. Each FunctionStats exposes name, calls, total_ns, min_ns, max_ns, median_ns, and stdev_ns — the same fields as --json output. Use `with tprof(maths) as results:` and then unpack or iterate results after the block completes. Developers building automated performance regression checks on Python code follow tooling like tprof on daily.dev.

1.5K Impressions