Skip to main content

Quick and easy python benchmarking.

Project description

Quickly find where your code is spending its time.

Build Status Downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bench-it-0.2.3.tar.gz (15.5 kB view hashes)

Uploaded Source

Built Distribution

bench_it-0.2.3-py2.py3-none-any.whl (18.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page