Simple benchmarking decorator
Project description
byo
A simple decorator to benchmark functions.
Installation
pip install byo
Usage
Just import the bench decorator and apply it to any function you want to benchmark!
from byo import bench
@bench
def benchmarked_function():
...
The decorator registers an atexit callback to print a report of function calls when the program finishes.
Example
Say we want to benchmark how long it takes to read and write some text to a file. We can use the bench decorator on those functions to profile them as follows.
from byo import bench
@bench
def read_file():
with open("lorem.txt", "r") as f:
f.read()
@bench
def write_file(text: str):
with open("lorem.txt", "w") as f:
f.write(text)
f = open("lorem.txt", "r")
LOREM = f.read()
f.close()
N = 1000
for _ in range(N):
read_file()
for _ in range(N):
write_file(LOREM)
Running this should output something like:
=== Report ===
| Function | Calls | Average (ms) | Median (ms) | Min (ms) | Max (ms) |
|------------|---------|----------------|---------------|------------|------------|
| read_file | 1000 | 0.0101 | 0.0092 | 0.0074 | 0.1033 |
| write_file | 1000 | 0.0326 | 0.0283 | 0.0224 | 1.0325 |
More examples can be found in /examples.
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 byo-0.1.0.tar.gz.
File metadata
- Download URL: byo-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c306b548c2d4f62bf69cdde8f84063d8092dc338fc06dd000c77f084d8ca0519
|
|
| MD5 |
9d5b1d0f7f9cb009ca116d7b958877b5
|
|
| BLAKE2b-256 |
1680164cffeb06e235fef4fbb7e89d2a620ff3eb3509514b099edb87b3a6bfb7
|
File details
Details for the file byo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: byo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dff85538c411e140648e5afc8202ac5d98d529e2f56289dfa324f9e1185d18f
|
|
| MD5 |
7d30c89bf6e595191b7042572437ac34
|
|
| BLAKE2b-256 |
59171f0d049825f566997970c80454c6cc4b806889bb5b5fbb2bf221982d81c6
|