Lightweight context-based library for benchmarking
Project description
Trainer ⏱
Lightweight benchmarking package with zero dependencies
Installation
pip install trainer-py
Usage
from trainer import Trainer
t = Trainer().round(2)
with t('metric1'):
time.sleep(0.5)
with t('metric2'):
time.sleep(0.3)
m = t.add_total('total').metrics
print(m)
output:
{
'metric1': {'start': 1656844808.09, 'end': 1656844808.59, 'interval': 0.5},
'metric2': {'start': 1656844808.59, 'end': 1656844808.89, 'interval': 0.3},
'total': {'start': 1656844808.09, 'end': 1656844808.89, 'interval': 0.8}
}
for more, see examples
Features
Contexts
- using Python contexts, you can indent specific parts of the code you want to benchmark
- each measured code part produces a 'metric' dictionary with name (key), start (epoch), end (epoch), interval (epoch)
- all metrics can be retrieved at any point by calling
trainer.metrics
Total Execution Time
- you can add the total execution time by executing
trainer.add_total()at the end - by default, the total time considers the first metric's start time as its
start, but it is possible to prematurely start measurement by calling
trainer.start_measuring()instead
Rounding
- all epoch timestamps can be rounded to any number of decimals using
trainer.round(<int>) - all epoch timestamps can be rounded to full seconds (making them
integers instead of floats) by executing
trainer.round()ortrainer.round(0)
Turning off Trainer
- to turn off trainer, the DummyTrainer class is provided. This class can be switched on, for example, based on a value of an environment variable
trainer = Trainer() if ENV_VAR else DummyTrainer()
- calling
.metricsat the end will always return in an empty dictionary which is falsy in Python. Your following code that uses themetricsdictionary can first do a check for this falsy value
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
trainer-py-0.2.0.tar.gz
(3.6 kB
view details)
File details
Details for the file trainer-py-0.2.0.tar.gz.
File metadata
- Download URL: trainer-py-0.2.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3fe2303d95aef58163c8c67ba4d7bad1c5f209b5f0b2a6918f2f8db1b2536a9
|
|
| MD5 |
6c0dcf654e23f344c89f72a6e4ed3f80
|
|
| BLAKE2b-256 |
adfc723c36afdeb1873f8976923cd1168a5d4958493023f4cdef1137996190bd
|