
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Horology
Conveniently measures the time of your loops, contexts and functions.
horology version | compatible python |
---|---|
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
The following 3 tools will let you measure practically any part of your Python code.
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
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)
@timed
decoratorfrom horology import timed
@timed
def foo():
...
Result:
>>> foo()
foo: 7.12 ms
Chose time unit and name:
@timed(unit='s', name='Processing took ')
def bar():
...
Result:
>>> bar()
Processing took 0.185 s
Timing
contextJust wrap your code using a with
statement
from horology import Timing
with Timing(name='Important calculations: '):
...
Result:
Important calculations: 12.4 s
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 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 are welcomed, see contribution guide.
Horology internally measures time with perf_counter
which provides the highest available resolution,
see docs.
FAQs
Conveniently measures the time of loops, contexts and functions.
We found that horology demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.