Time a block of code
Project description
harrison
========
Time a block of code.
Use as the context expression of a `with` statement:
```pyconsole
>>> from harrison import Timer
>>> with Timer() as t:
>>> ...
>>> print t.elapsed_time_ms
12345
```
When a description string is passed on initialization, the elapsed time will
be printed on completion, keyed by this description.
```pyconsole
>>> with Timer('My expensive block of code'):
>>> ...
My expensive block of code: 12345 ms
```
You can also start and stop a Timer explicitly:
```py
timer = Timer()
timer.start()
some_expensive_function(...)
print timer.elapsed_time_s
another_expensive_function(...)
timer.stop()
print timer.elapsed_time_s
```
You can also time each execution of a function using a decorator:
```py
from harrison import profile
@profile('Describes the function')
def some_function():
pass
# Without args, the function name (e.g. 'some_function') will be used
# as the description.
@profile()
def another_function():
pass
```
You can also use `RegisteredTimer`, which groups together a bunch of named
timers, provides utilities for serializing their times, and an optional global
timer registry.
Named after John Harrison, the English carpenter and clockmaker who
invented the [marine chronometer][].
[John Harrison]: https://en.wikipedia.org/wiki/John_Harrison
[marine chronometer]: https://en.wikipedia.org/wiki/Marine_chronometer
Similar libraries
-----------------
This is similar to the library [contexttimer][], but that library is licensed
under the GPLv3 which is more restrictive than two-clause BSD license used
here.
[contexttimer]: https://github.com/brouberol/contexttimer
Development
-----------
```sh
pip install -r requirements_dev.txt
rake lint
```
Contribute
----------
- Issue Tracker: https://github.com/bodylabs/harrison/issues
- Source Code: https://github.com/bodylabs/harrison
Pull requests welcome!
Support
-------
If you are having issues, please let us know.
License
-------
The project is licensed under the two-clause BSD license.
========
Time a block of code.
Use as the context expression of a `with` statement:
```pyconsole
>>> from harrison import Timer
>>> with Timer() as t:
>>> ...
>>> print t.elapsed_time_ms
12345
```
When a description string is passed on initialization, the elapsed time will
be printed on completion, keyed by this description.
```pyconsole
>>> with Timer('My expensive block of code'):
>>> ...
My expensive block of code: 12345 ms
```
You can also start and stop a Timer explicitly:
```py
timer = Timer()
timer.start()
some_expensive_function(...)
print timer.elapsed_time_s
another_expensive_function(...)
timer.stop()
print timer.elapsed_time_s
```
You can also time each execution of a function using a decorator:
```py
from harrison import profile
@profile('Describes the function')
def some_function():
pass
# Without args, the function name (e.g. 'some_function') will be used
# as the description.
@profile()
def another_function():
pass
```
You can also use `RegisteredTimer`, which groups together a bunch of named
timers, provides utilities for serializing their times, and an optional global
timer registry.
Named after John Harrison, the English carpenter and clockmaker who
invented the [marine chronometer][].
[John Harrison]: https://en.wikipedia.org/wiki/John_Harrison
[marine chronometer]: https://en.wikipedia.org/wiki/Marine_chronometer
Similar libraries
-----------------
This is similar to the library [contexttimer][], but that library is licensed
under the GPLv3 which is more restrictive than two-clause BSD license used
here.
[contexttimer]: https://github.com/brouberol/contexttimer
Development
-----------
```sh
pip install -r requirements_dev.txt
rake lint
```
Contribute
----------
- Issue Tracker: https://github.com/bodylabs/harrison/issues
- Source Code: https://github.com/bodylabs/harrison
Pull requests welcome!
Support
-------
If you are having issues, please let us know.
License
-------
The project is licensed under the two-clause BSD license.
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
harrison-1.0.0.tar.gz
(4.5 kB
view details)
File details
Details for the file harrison-1.0.0.tar.gz
.
File metadata
- Download URL: harrison-1.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e01c3bcc0792385d9bd8e8f4ca696c11d17ab992e52f3177b7afe8295bb2b37 |
|
MD5 | 4094d7d718be8c496521ae7fb83095f1 |
|
BLAKE2b-256 | 1b39b2414b8e3634aa12f4b2064795830f49e32cc312bc62e274757387e6ec3e |