Horology
Conveniently measures the time of your loops, contexts and functions.
Installation
| horology version | compatible python |
|---|---|
| 1.4.2 | 3.10-3.14 |
| 1.4.1 | 3.10-3.13 |
| 1.4 | 3.10-3.12 |
| 1.3 | 3.8-3.11 |
| 1.2 | 3.6-3.9 |
| 1.1 | 3.6-3.8 |
Horology can be installed with PIP. It has no dependencies.
pip install horology
Usage
The following 3 tools will let you measure practically any part of your Python code.
Timing an iterable (list, tuple, generator, etc)
Quick example
from horology import Timed
animals = ['cat', 'dog', 'crocodile']
for x in Timed(animals):
feed(x)
Result:
iteration 1: 12.0 s
iteration 2: 8.00 s
iteration 3: 100 s
total 3 iterations in 120 s
min/median/max: 8.00/12.0/100 s
average (std): 40.0 (52.0) s
Customization
You can specify where (if at all) you want each iteration and summary to be printed, eg.:
for x in Timed(animals, unit='ms',
iteration_print_fn=logger.debug,
summary_print_fn=logger.info):
feed(x)
Timing a function with a @timed decorator
Quick example
from horology import timed
@timed
def foo():
...
Result:
>>> foo()
foo: 7.12 ms
Customization
Chose time unit and name:
@timed(unit='s', name='Processing took ')
def bar():
...
Result:
>>> bar()
Processing took 0.185 s
Timing part of code with a Timing context
Quick example
Just wrap your code using a with statement
from horology import Timing
with Timing(name='Important calculations: '):
...
Result:
Important calculations: 12.4 s
Customization
You can suppress default printing and directly use measured time (also within context)
with Timing(print_fn=None) as t:
...
make_use_of(t.interval)
Time units
Time units are by default automatically adjusted, for example you will see
foo: 7.12 ms rather than foo: 0.007 s. If you don't like it, you can
override this by setting the unit argument with one of these names:
['ns', 'us', 'ms', 's', 'min', 'h', 'd'].
Contributions
Contributions are welcomed, see contribution guide.
Internals
Horology internally measures time with perf_counter which provides the highest available resolution,
see docs.
Release files for horology 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| horology-1.4.2.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| horology-1.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / horology-1.4.2.tar.gz
| Download URL | horology-1.4.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
913536ed4ad4b33fb4d4fca564647c1c03c1de75525b91217b1e782405a6ca39
|
|
BLAKE2b-256 checksum How to use checksums |
4c432aa875fc7cde517fc42ad11d38f977439c491336fb1217877767585f0101
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.11.5 Windows/10
|
Release files / horology-1.4.2-py3-none-any.whl
| Download URL | horology-1.4.2-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37f107450fe8ce1e8adc8b85f8f3eff4609d6ced3d76cb381c219e1ab3fb1b1d
|
|
BLAKE2b-256 checksum How to use checksums |
022ea2aa307057c4be927a894141ec2d42c62d1f656bb413fa81a5b44edf2761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.11.5 Windows/10
|