Skip to main content

harrison

Time a block of code.

version python version license build code style

Use as the context expression of a with statement:

>>> 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.

>>> with Timer('My expensive block of code'):
>>>     ...
My expensive block of code: 12345 ms

You can also start and stop a Timer explicitly:

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:

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.

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.

Development

./dev.py init
./dev.py test

Contribute

Pull requests welcome!

Support

If you are having issues, please let us know.

Acknowledgements

This project was packaged by Paul Melnikow while at Body Labs. Thanks to Body Labs for the repository transfer.

License

The project is licensed under the two-clause BSD license.

Metadata

Release files for harrison 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for harrison 2.0.0
File Size Uploaded
harrison-2.0.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for harrison 2.0.0
File Interpreter ABI Platform
harrison-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / harrison-2.0.0.tar.gz

Download URL harrison-2.0.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ddd1abe199429c68fcae31c2774e556c7a6cd36ebd665f2363ea084b0cf9d673
BLAKE2b-256 checksum
How to use checksums
1de6537317d1be4d61e40600ec90eb3fadf2cb7f3d35cc28c8f7c32c3a6386fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5

Release files / harrison-2.0.0-py3-none-any.whl

Download URL harrison-2.0.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e29a352e5a4082d9967b15d52ac4c703dcbddc4719292dea02810727f2cad02
BLAKE2b-256 checksum
How to use checksums
16d464fc6f1704c646b43bb463da51f12d66f691bc995d6dce577ae89a2fc52b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.2.1

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page