Quick and easy python benchmarking.
Project description
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 line A to line B. It helps detect unoptimized code.
Installation
pip install bench-it
Example
>>> from benchit import BenchIt >>> b = BenchIt() # starts the timer >>> # do stuff >>> b.mark("Stuff Done") >>> for i in range(1,5): ... b.mark("In loop") ... pass # more stuff done >>> b.mark("More stuff completed") >>> b.display() +----------------------+----------+------+-------+----------+---------+---------+ | Marker | Method | Line | Loops | Avg Time | Runtime | Percent | +----------------------+----------+------+-------+----------+---------+---------+ | Stuff Done | <module> | 2 | 1 | 0.59003 | 0.59003 | 5.86 | | In loop | <module> | 2 | 4 | 1.37800 | 5.51199 | 54.78 | | More stuff completed | <module> | 6 | 1 | 3.60235 | 3.60235 | 35.80 | | _display | <module> | 53 | 1 | 0.35842 | 0.35842 | 3.56 | +----------------------+----------+------+-------+----------+---------+---------+ Total runtime: 10.06
How to Use
Instantiating the class starts the timer.
b = BenchIt()
Set a marker after some code.
b.mark("Stuff Done")
Stop and display the table for analysis.
b.display()
Methods
benchit.__init__() Instantiate and start the timer.
benchit.mark(marker_name) Add marker at this point.
benchit.stop() Stop the timer.
benchit.display() Display the table. Stops the timer if running.
Credits
Special thanks Luke Maurits for `prettytable <https://pypi.python.org/pypi/PrettyTable>`__
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
Hashes for bench_it-0.2.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a805f93610d1e6bb072b68b652924e7e446f52547b509dc953536090d9afbe1 |
|
MD5 | da16360357e7a2e60273a35b578c6dd3 |
|
BLAKE2b-256 | a78ff1500bcdb7014e21c0822f19c936b4f6401f4ce4eec2744e9b9d50242827 |