Quickly find where your code is spending its time.
Benchit is intended to be a minimalistic library that times how long it takes to get from point A to point B. It helps detect unoptimized code.
Benchit is only compatible with python 3. For python 2 support, use benchit==0.2.6 (https://pypi.python.org/pypi/bench-it/0.2.6)
Installation
pip install bench-it
Example
from benchit import BenchIt
from time import sleep
def demo_benchmark():
b = BenchIt() # starts the timer
# do stuff
sleep(1); b() # Add marker after this code. Code used as marker name.
sleep(.2);
sleep(.3);
sleep(.4);
b("More stuff done") # Add a custom named marker
for i in range(1, 5):
sleep(.1); b() # Code can be marked in a loop
b.display() # Display output as a table
demo_benchmark()
BenchIt
+-----------------+----------------+------------+------+----------+---------+---------+
| Marker | Method | Line | Hits | Avg Time | Runtime | Percent |
+-----------------+----------------+------------+------+----------+---------+---------+
| sleep(1) | demo_benchmark | demo.py:9 | 1 | 1.01341 | 1.01341 | 43.33 |
| More stuff Done | demo_benchmark | demo.py:14 | 1 | 0.91278 | 0.91278 | 39.03 |
| sleep(.1) | demo_benchmark | demo.py:17 | 4 | 0.10306 | 0.41223 | 17.63 |
+-----------------+----------------+------------+------+----------+---------+---------+
Total runtime: 2.33860
How to Use
Instantiating the class starts the timer. BenchIt is run as a singleton. Re-instantiating anywhere in your code will pull in the previously instantiated timer. To create a new timer, initialize BenchIt with a unique name.
b = BenchIt()
b2 = BenchIt() # b == b2
b3 = BenchIt("Timer A") # b != b3
Set a marker after some code.
call_a_method(); b() # Quickly add a marker after a method
method1()
method2()
b("Two methods called") # Or create a manual marker after a chunk of code
Stop and display the table for analysis.
b.display()
Methods
benchit.__init__() Instantiate and start the timer.
benchit.__call__(marker_name) Add marker at this point.
benchit.stop() Optionally, stop the timer at a point.
benchit.display() Display the table. Stops the timer if running.
Credits
Special thanks Luke Maurits for prettytable*
Metadata
Release files for bench-it 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bench-it-1.0.1.tar.gz | 16.2 kB | Without provenance | Details for bench-it-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bench_it-1.0.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for bench_it-1.0.1-py2.py3-none-any.whl |
Total release size: 35.3 kB
Release files / bench-it-1.0.1.tar.gz
| Download URL | bench-it-1.0.1.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e14c4b72df01d2470fa73200c03c3283b4a5f53d257a728af8e4adbde76d36c
|
|
BLAKE2b-256 checksum How to use checksums |
841d715aeb5db587ecd462c0be5ed69959466d6681a296905a8fc40722a15d99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / bench_it-1.0.1-py2.py3-none-any.whl
| Download URL | bench_it-1.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d7f588f99de025735f00e24c8bc56b32da0a86f2e9fa6fe97befaa878cca2a46
|
|
BLAKE2b-256 checksum How to use checksums |
e3c47f91020f875a0e7f1ca880b5ac7c047e021366408f608e106c60799670e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for bench-it 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.