Name | tree-timer JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | A hierarchical performance timer for structured profiling |
upload_time | 2025-07-31 14:23:44 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | MIT License Copyright (c) 2025 okenakt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
timer
timing
performance
profiling
benchmark
tree
nested
structured
context-manager
with-statement
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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.


---
## 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
```bash
pip install tree-timer
```
---
## Usage
### 1. Simple use
```python
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()`
```python
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()`
```python
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
```python
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](LICENSE)
Raw data
{
"_id": null,
"home_page": null,
"name": "tree-timer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "timer, timing, performance, profiling, benchmark, tree, nested, structured, context-manager, with-statement",
"author": null,
"author_email": "Takamu Kaneko <19400343+okenakt@users.noreply.github.com>",
"download_url": "https://files.pythonhosted.org/packages/2e/6c/b72a13d8e2ade4379a83d7d3575067199f809edda1f5bb57f40eed8fc973/tree_timer-0.1.0.tar.gz",
"platform": null,
"description": "# TreeTimer\n\nA hierarchical performance timer for measuring nested execution scopes in Python. \nSupports context-based timing, named sub-scopes, repeated series tracking, and structured reporting.\n\n\n\n\n---\n\n## Features\n\n- \u23f1 Simple `with`-based timing API\n- \ud83c\udf32 Tree-style nested timing scopes\n- \ud83d\udd01 Support for repeated timing series (e.g. epochs, batches)\n- \ud83d\udce6 `to_dict()` output for visualization or structured logging\n\n---\n\n## Installation\n\n```bash\npip install tree-timer\n```\n\n---\n\n## Usage\n\n### 1. Simple use\n\n```python\nfrom tree_timer import TreeTimer\nimport time\n\nwith TreeTimer() as timer:\n time.sleep(0.1)\n\nprint(timer)\n```\n\n```\nroot: 0.100123s\n```\n\n---\n\n### 2. Nested scopes with `add_scope()`\n\n```python\nwith TreeTimer() as timer:\n with timer.add_scope(\"load_data\"):\n time.sleep(0.05)\n with timer.add_scope(\"process_data\"):\n time.sleep(0.08)\n\nprint(timer)\n```\n\n```\nroot: 0.130456s\n load_data: 0.050123s\n process_data: 0.080333s\n```\n\n---\n\n### 3. Loop timing with `add_series()`\n\n```python\nwith TreeTimer() as timer:\n steps = timer.add_series(\"steps\", 3)\n for step in steps:\n with step:\n time.sleep(0.03)\n\nprint(timer)\n```\n\n```\nroot: 0.090876s\n steps: 0.090876s\n [0]: 0.030141s\n [1]: 0.030251s\n [2]: 0.030484s\n```\n\n---\n\n### 4. Combined use with parallel execution\n\n```python\nfrom tree_timer import TreeTimer\nfrom concurrent.futures import ThreadPoolExecutor\nimport time\n\ndef run_task(timer):\n with timer:\n time.sleep(0.03)\n\nwith TreeTimer() as timer:\n with timer.add_scope(\"pipeline\") as pipeline:\n with pipeline.add_scope(\"load\"):\n time.sleep(0.02)\n\n steps = pipeline.add_series(\"parallel_steps\", 4)\n with ThreadPoolExecutor() as executor:\n executor.map(run_task, steps)\n\n with pipeline.add_scope(\"finalize\"):\n time.sleep(0.01)\n\nprint(timer)\n```\n\n```\nroot: 0.063421s\n pipeline: 0.063421s\n load: 0.020114s\n parallel_steps: 0.120548s\n [0]: 0.030102s\n [1]: 0.030184s\n [2]: 0.030120s\n [3]: 0.030142s\n finalize: 0.010216s\n```\n\n> \ud83d\udca1 Tasks in `parallel_steps` run concurrently using ThreadPoolExecutor, while the surrounding `load` and `finalize` scopes are timed sequentially.\n\n---\n\n## License\n\n[MIT](LICENSE)\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2025 okenakt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A hierarchical performance timer for structured profiling",
"version": "0.1.0",
"project_urls": {
"Documentation": "https://github.com/okenakt/tree-timer#readme",
"Homepage": "https://github.com/okenakt/tree-timer",
"Issues": "https://github.com/okenakt/tree-timer/issues",
"Repository": "https://github.com/okenakt/tree-timer"
},
"split_keywords": [
"timer",
" timing",
" performance",
" profiling",
" benchmark",
" tree",
" nested",
" structured",
" context-manager",
" with-statement"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2d56811d0999e21593d0d25d9dcfcac3c976914aebdefde8bbde95488631ac30",
"md5": "38e042f3ea0159109db43639ea5b7278",
"sha256": "fe02a7a0e4a5f9bd0324f6be1734a3689eba26cb9c4d64a0285a9f64374a7217"
},
"downloads": -1,
"filename": "tree_timer-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "38e042f3ea0159109db43639ea5b7278",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 5806,
"upload_time": "2025-07-31T14:23:43",
"upload_time_iso_8601": "2025-07-31T14:23:43.160274Z",
"url": "https://files.pythonhosted.org/packages/2d/56/811d0999e21593d0d25d9dcfcac3c976914aebdefde8bbde95488631ac30/tree_timer-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2e6cb72a13d8e2ade4379a83d7d3575067199f809edda1f5bb57f40eed8fc973",
"md5": "754ea17f9dd7b5777985ea68aaa3bfc4",
"sha256": "b5103ce366414ef2d0ff51d568de321fa9db67f316363ad216c1fa2b1d90aabd"
},
"downloads": -1,
"filename": "tree_timer-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "754ea17f9dd7b5777985ea68aaa3bfc4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 5853,
"upload_time": "2025-07-31T14:23:44",
"upload_time_iso_8601": "2025-07-31T14:23:44.610775Z",
"url": "https://files.pythonhosted.org/packages/2e/6c/b72a13d8e2ade4379a83d7d3575067199f809edda1f5bb57f40eed8fc973/tree_timer-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-31 14:23:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "okenakt",
"github_project": "tree-timer#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tree-timer"
}