A lightweight and convenient package for precise performance timing and analysis in Python.
Project description
Perfed
Perfed is a lightweight and easy-to-use package for measuring and analyzing execution times in Python code. It is a wrapper around time.perf_counter_ns() to provide precise performance timing that provides an intuitive interface and convenient tools for displaying and analyzing the results.
Features
✅ Measure execution time of code blocks and functions
✅ Display results as tables in the console
✅ Output timings as a pandas DataFrame for further analysis
✅ Compute aggregated statistics (average, min, max) for decorated functions
Requirements
- Python 3.12 or higher
Installation
pip install perfed
Usage
Using TimerManager
Measure and manage multiple timers concurrently.
import time
from IPython.display import display as ipy_display
from perfed.timer_manager import TimerManager
tm = TimerManager()
tm.start("first")
time.sleep(0.2)
tm.stop("first")
tm.start("second")
time.sleep(0.3)
tm.stop("second")
with tm.start("third"):
time.sleep(0.4)
print("~~~~~~~~~~TIMERS~~~~~~~~~~")
tm.show(unit="sec")
print("~~~~~~~~~~DATAFRAME~~~~~~~~~~")
ipy_display(tm.to_dataframe("ns"))
"""
Output:
~~~~~~~~~~TIMERS~~~~~~~~~~
Timer Elasped Time
------- --------------
first 0.2008
second 0.300584
third 0.400186
~~~~~~~~~~DATAFRAME~~~~~~~~~~
Timer Elasped Time
0 first 200800500.0
1 second 300583900.0
2 third 400186100.0
"""
Using TimerDecorator
Automatically measure execution time of decorated functions and view aggregate statistics.
import time
from perfed.timer_decorator import TimerDecorator
@TimerDecorator.decorate("foo_tm")
def foo(x: int):
print(x)
time.sleep(0.2)
@TimerDecorator.decorate("bar_tm")
def bar(x: str):
print(x)
time.sleep(0.3)
foo(49)
foo(200)
foo(455)
bar("cat")
bar("dog")
print("~~~~~~~~~~FOO TIMERS~~~~~~~~~~")
TimerDecorator.get_manager("foo_tm").show()
print("~~~~~~~~~~FOO STATS~~~~~~~~~~")
TimerDecorator.get_manager("foo_tm").show_stats()
print("~~~~~~~~~~BAR TIMERS~~~~~~~~~~")
TimerDecorator.get_manager("bar_tm").show()
print("~~~~~~~~~~BAR STATS~~~~~~~~~~")
TimerDecorator.get_manager("bar_tm").show_stats()
"""
Output:
49
200
455
cat
dog
~~~~~~~~~~FOO TIMERS~~~~~~~~~~
Timer Elasped Time
--------- --------------
foo_tm(1) 0.200905
foo_tm(2) 0.200426
foo_tm(3) 0.200805
~~~~~~~~~~FOO STATS~~~~~~~~~~
Stat Value
------- --------
Average 0.200712
Max 0.200905
Min 0.200426
~~~~~~~~~~BAR TIMERS~~~~~~~~~~
Timer Elasped Time
--------- --------------
bar_tm(1) 0.30011
bar_tm(2) 0.30071
~~~~~~~~~~BAR STATS~~~~~~~~~~
Stat Value
------- -------
Average 0.30041
Max 0.30071
Min 0.30011
"""
Why Perfed?
Perfed is inspired by perfcounters. I created this project to add some original ideas and to share a simple, flexible performance timing tool with the community.
Project details
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 perfed-0.1.1.tar.gz.
File metadata
- Download URL: perfed-0.1.1.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
343b69629b800460c3078f75970a7c50592dd54804f5af7e3068db9a37d45c3d
|
|
| MD5 |
e73a36feaddb7c97b85f3ff387d202d7
|
|
| BLAKE2b-256 |
15a567c7167ae9725ddd9e69fbb6f39367fde1bfc920cdb1151d35c9ad9fb704
|
Provenance
The following attestation bundles were made for perfed-0.1.1.tar.gz:
Publisher:
publish.yaml on sohenze/perfed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perfed-0.1.1.tar.gz -
Subject digest:
343b69629b800460c3078f75970a7c50592dd54804f5af7e3068db9a37d45c3d - Sigstore transparency entry: 229298102
- Sigstore integration time:
-
Permalink:
sohenze/perfed@2619faf11c7c516a6ed6d0be0b3725d498062ccd -
Branch / Tag:
refs/tags/perfed-v0.1.1 - Owner: https://github.com/sohenze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2619faf11c7c516a6ed6d0be0b3725d498062ccd -
Trigger Event:
release
-
Statement type:
File details
Details for the file perfed-0.1.1-py3-none-any.whl.
File metadata
- Download URL: perfed-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78521c3f03cfe129876465339ea712e204f9cf7bbddaf1b292331ee363670c6b
|
|
| MD5 |
c124e0077f09d97f0ab4c1cbc080edcf
|
|
| BLAKE2b-256 |
06d5c2310932c61527f76b1192b1d962d86d6011420fd1da8a1b3f05054c2e88
|
Provenance
The following attestation bundles were made for perfed-0.1.1-py3-none-any.whl:
Publisher:
publish.yaml on sohenze/perfed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perfed-0.1.1-py3-none-any.whl -
Subject digest:
78521c3f03cfe129876465339ea712e204f9cf7bbddaf1b292331ee363670c6b - Sigstore transparency entry: 229298104
- Sigstore integration time:
-
Permalink:
sohenze/perfed@2619faf11c7c516a6ed6d0be0b3725d498062ccd -
Branch / Tag:
refs/tags/perfed-v0.1.1 - Owner: https://github.com/sohenze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2619faf11c7c516a6ed6d0be0b3725d498062ccd -
Trigger Event:
release
-
Statement type: