Hierarchical timing utility with nested context manager support
Project description
muTimer
muTimer is a hierarchical timing utility with nested context manager support. It provides fine-grained timing of code sections.
Features
- Nested timing contexts that track parent-child relationships
- Accumulation of time across multiple calls to the same timer
- Call counting for repeated operations
- Hierarchical summary output in tabular format
- Optional depth limiting for nested timers
Usage
from muTimer import Timer
timer = Timer()
with timer("outer"):
# some code
with timer("inner"):
# nested code
with timer("inner"): # called again - time accumulates
# more nested code
timer.print_summary()
Output:
==============================================================================
Timing Summary
==============================================================================
Name Total Calls Average % Parent
------------------------------ ------------ -------- ------------ ----------
outer 22.55 ms 1 - -
inner 12.50 ms 2 6.25 ms 55.4%
(other) 10.06 ms - - 44.6%
==============================================================================
Memory Tracking
You can also track memory usage (Resident Set Size) by enabling track_memory=True. This requires the psutil package.
import time
from muTimer import Timer
# Create a timer with memory tracking enabled
timer = Timer(track_memory=True)
with timer("outer"):
# allocate some memory
large_list = [0] * 1000000
time.sleep(0.01)
with timer("inner"):
another_list = [1] * 2000000
time.sleep(0.01)
with timer("inner"):
more_memory = [2] * 500000
time.sleep(0.005)
timer.print_summary()
Output:
============================================================================================
Timing Summary
============================================================================================
Name Total Calls Average % Parent Memory
------------------------------ ------------ -------- ------------ ---------- ------------
outer 33.74 ms 1 - - 26.78 MB
inner 20.52 ms 2 10.26 ms 60.8% 19.12 MB
(other) 13.23 ms - - 39.2% 7.66 MB
============================================================================================
License
muTimer is distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mutimer-1.0.0.tar.gz.
File metadata
- Download URL: mutimer-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb2fb942f86f49e2c2f590b46df0231fb70b32560a24065ea57f95a1c332d358
|
|
| MD5 |
6928933adbfd319f56c97295518cd66a
|
|
| BLAKE2b-256 |
1a752708d0022bb88c4073958a0761a132913db66b0feca6a0bc0e851d4d0771
|
File details
Details for the file mutimer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mutimer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e3d7c7d6747c5e3d053b0cb3d01c06256c3664afb3197ae62b08eac5dd7bcef
|
|
| MD5 |
48fe9d97dc70c988240be308f2db8b68
|
|
| BLAKE2b-256 |
e6133a06381729ad3edf4daedb923928b48351a4beb2e5c16bbc221e456e2c48
|