measure time conveniently
Project description
Horology
conveniently measures time of your for-loops, contexts and functions.
Following 3 tools let you measure practically any part of your Python code.
Usage
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.00 s
iteration 2: 8.00 s
iteration 3: 100.00 s
total 3 iterations in 120.00 s
min/median/max: 8.00/12.00/100.00 s
average (std): 40.00 (52.00) s
More cool stuff:
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():
pass
Result:
>>> foo()
foo: 7.12 ms
More cool stuff:
Personalize time unit and name
@timed(unit='s', name='Processing took ')
def bar():
pass
Result:
>>> bar()
Processing took 0.18 s
Timing part of code with a Timing
context
Quick example
Just wrap your code using with
statement
from horology import Timing
with Timing(name='Important calculations: '):
pass
Result:
Important calculations: 12.43 s
More cool stuff:
You can suppress default printing and directly use measured time (also within context)
with Timing(print_fn=None) as t:
pass
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 overwrite this by setting unit
argument with one of those:
['ns', 'us', 'ms', 's', 'min', 'h', 'd']
.
Contributions
- Contributions are welcomed
- Make sure that all tests pass (both unittests and doctests), you can run them all with:
nosetests -vv --with-doctest --doctest-options=+ELLIPSIS
- If any questions, feel free to contact me.
Internals:
TTT internally measures time with perf_counter
which provides highest available resolution,
see docs.
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
Built Distribution
File details
Details for the file horology-1.0.0.tar.gz
.
File metadata
- Download URL: horology-1.0.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ba5a1832f26096f04abd492e5a753b0196372de687ffa4928459d5acca0c8a6 |
|
MD5 | afbae28268f58495ecc75bbc0f044f38 |
|
BLAKE2b-256 | 5ab412f91155e6241b754345c76f5db934cfb6aa96d33c5f1e9bb731152bd296 |
File details
Details for the file horology-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: horology-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea2d4425635756eb97278e11fc4ff407f2e40c8b9874b8467943e1a0a67c5811 |
|
MD5 | f5af8d551ce35325a476c02aadaf9065 |
|
BLAKE2b-256 | 863ccf6b81abe0f77310f7cf743e7c1599ccb5f80ca2e01341151365e67dc75b |