Skip to main content

harrison

Time a block of code.

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

pip install -r requirements_dev.txt
rake lint

Contribute

Pull requests welcome!

Support

If you are having issues, please let us know.

License

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

Metadata

Release files for metaboharrison 1.2.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 metaboharrison 1.2.0
File Size Uploaded Provenance Actions
metaboharrison-1.2.0.tar.gz 5.9 kB Without provenance Details for metaboharrison-1.2.0.tar.gz

Release files / metaboharrison-1.2.0.tar.gz

Download URL metaboharrison-1.2.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
04aba6c0ca2c0c94c66d2a34c5376aefd60b703769b94335ba0f89e5bcd4a952
BLAKE2b-256 checksum
How to use checksums
79876e651781d1ba2be3a3821a146968bc0faa4967d8c2686c08e4cc3bb57ffa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.16

Security for metaboharrison 1.2.0

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.

Release history Release notifications | RSS feed

This release

1.2.0 This release

1 release file No provenance

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