Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Time a block of code

Project Description


Time a block of code.

Use as the context expression of a ``with`` statement:

.. code:: pyconsole

>>> from harrison import Timer
>>> with Timer() as t:
>>> ...
>>> print t.elapsed_time_ms

When a description string is passed on initialization, the elapsed time
will be printed on completion, keyed by this description.

.. code:: pyconsole

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

You can also start and stop a Timer explicitly:

.. code:: py

timer = Timer()

print timer.elapsed_time_s

print timer.elapsed_time_s

You can also time each execution of a function using a decorator:

.. code:: py

from harrison import profile

@profile('Describes the function')
def some_function():

# Without args, the function name (e.g. 'some_function') will be used
# as the description.
def another_function():

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.


.. code:: sh

pip install -r requirements_dev.txt
rake lint


- Issue Tracker:
- Source Code:

Pull requests welcome!


If you are having issues, please let us know.


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

Release History

This version
History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(5.8 kB) Copy SHA256 Hash SHA256
Source None Jun 27, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers