Skip to main content

TreeTimer

A hierarchical performance timer for measuring nested execution scopes in Python.
Supports context-based timing, named sub-scopes, repeated series tracking, and structured reporting.

PyPI Python


Features

  • ⏱ Simple with-based timing API
  • 🌲 Tree-style nested timing scopes
  • 🔁 Support for repeated timing series (e.g. epochs, batches)
  • 📦 to_dict() output for visualization or structured logging

Installation

pip install tree-timer

Usage

1. Simple use

from tree_timer import TreeTimer
import time

with TreeTimer() as timer:
    time.sleep(0.1)

print(timer)
root: 0.100123s

2. Nested scopes with add_scope()

with TreeTimer() as timer:
    with timer.add_scope("load_data"):
        time.sleep(0.05)
    with timer.add_scope("process_data"):
        time.sleep(0.08)

print(timer)
root: 0.130456s
  load_data: 0.050123s
  process_data: 0.080333s

3. Loop timing with add_series()

with TreeTimer() as timer:
    steps = timer.add_series("steps", 3)
    for step in steps:
        with step:
            time.sleep(0.03)

print(timer)
root: 0.090876s
  steps: 0.090876s
    [0]: 0.030141s
    [1]: 0.030251s
    [2]: 0.030484s

4. Combined use with parallel execution

from tree_timer import TreeTimer
from concurrent.futures import ThreadPoolExecutor
import time

def run_task(timer):
    with timer:
        time.sleep(0.03)

with TreeTimer() as timer:
    with timer.add_scope("pipeline") as pipeline:
        with pipeline.add_scope("load"):
            time.sleep(0.02)

        steps = pipeline.add_series("parallel_steps", 4)
        with ThreadPoolExecutor() as executor:
            executor.map(run_task, steps)

        with pipeline.add_scope("finalize"):
            time.sleep(0.01)

print(timer)
root: 0.063421s
  pipeline: 0.063421s
    load: 0.020114s
    parallel_steps: 0.120548s
      [0]: 0.030102s
      [1]: 0.030184s
      [2]: 0.030120s
      [3]: 0.030142s
    finalize: 0.010216s

💡 Tasks in parallel_steps run concurrently using ThreadPoolExecutor, while the surrounding load and finalize scopes are timed sequentially.


License

MIT

Metadata

Release files for tree-timer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-timer 0.1.0
File Size Uploaded Provenance Actions
tree_timer-0.1.0.tar.gz 5.9 kB Without provenance Details for tree_timer-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tree-timer 0.1.0
File Interpreter ABI Platform Actions
tree_timer-0.1.0-py3-none-any.whl Python 3 none any Details for tree_timer-0.1.0-py3-none-any.whl

Total release size: 11.7 kB

Release files / tree_timer-0.1.0.tar.gz

Download URL tree_timer-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b5103ce366414ef2d0ff51d568de321fa9db67f316363ad216c1fa2b1d90aabd
BLAKE2b-256 checksum
How to use checksums
2e6cb72a13d8e2ade4379a83d7d3575067199f809edda1f5bb57f40eed8fc973
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release files / tree_timer-0.1.0-py3-none-any.whl

Download URL tree_timer-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe02a7a0e4a5f9bd0324f6be1734a3689eba26cb9c4d64a0285a9f64374a7217
BLAKE2b-256 checksum
How to use checksums
2d56811d0999e21593d0d25d9dcfcac3c976914aebdefde8bbde95488631ac30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Security for tree-timer 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page