Conveniently measures the time of your loops, contexts and functions.

Overview

Horology

Language grade: Python Total alerts Downloads PyPI version

CircleCI

Conveniently measures the time of your loops, contexts and functions.

Installation

Simply:

pip install horology

Works with python versions 3.6, 3.7, 3.8 and 3.9. Tested on Linux, Windows and MacOS.

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

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():
    ...

Result:

>>> foo()
foo: 7.12 ms

More cool stuff:

Personalize 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

More cool stuff:

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.

You might also like...
Helpful functions for use alongside the rich Python library.

🔧 Rich Tools A python package with helpful functions for use alongside with the rich python library. 󠀠󠀠 The current features are: Convert a Pandas

Run functions in parallel easily, with their results typed correctly!

typesafe_parmap pip install pip install typesafe-parmap Run functions in parallel safely with typesafe parmap! GitHub: https://github.com/thejaminato

Python @deprecat decorator to deprecate old python classes, functions or methods.

deprecat Decorator Python @deprecat decorator to deprecate old python classes, functions or methods. Installation pip install deprecat Usage To use th

Dill_tils is a package that has my commonly used functions inside it for ease of use.

DilllonB07 Utilities Dill_tils is a package that has my commonly used functions inside it for ease of use. Installation Anyone can use this package by

A collection of utility functions to prototype geometry processing research in python

gpytoolbox This repo is a work in progress and contains general utility functions I have needed to code while trying to work on geometry process resea

A simple example for calling C++ functions in Python by `ctypes`.

ctypes-example A simple example for calling C++ functions in Python by ctypes. Features call C++ function int bar(int* value, char* msg) with argumene

Gradually automate your procedures, one step at a time

Gradualist Gradually automate your procedures, one step at a time Inspired by https://blog.danslimmon.com/2019/07/15/ Features Main Features Converts

A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use that mirror

Kali Mirror Finder Using Single Python File A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use tha

jsoooooooon derulo - Make sure your 'jason derulo' is featured as the first part of your json data

jsonderulo Make sure your 'jason derulo' is featured as the first part of your json data Install: # python pip install jsonderulo poetry add jsonderul

Comments
  • [ADD] iterations in decorator

    [ADD] iterations in decorator

    When using horology, I often end up putting in a for loop for performace based timings over many iterations.

    By adding it to the decorator, it can help for quick analysis.

    If you are happy I can also look at adding the same functionality to the context manage.

    I am unsure how this would fit with the timed_iterable, maybe conflicts, maybe not??

    I will let you decide :)

    opened by johnashu 10
Releases(v1.2.0)
  • v1.2.0(Oct 1, 2021)

    Link to this version on the The Python Package Index.

    Features

    • Use always 3 significant digits when formatting output strings. Such formatting is much more elegant and avoids adding decimal points for integers.

    Fixes

    • Wrong link in pepy badge.

    Docs

    • All docs were rewritten in beautiful numpy style.

    Tests and deployment

    • Add CI for python 3.9.
    • Use poetry to build and deploy
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jan 14, 2020)

    Feature

    • Time units allow aliases, by @johnashu

    Fix

    • Not rescaling total time in Timed iterable - fixed

    Docs

    • Add contribution guide
    • Add bug report template
    • Add feature request template
    • Add doc strings in tformatter module
    • Add badges to readme

    Tests:

    • Add CI for python 3.6-3.8
    • Add tests of Timed iterable summary
    • Add tests of tformatter exception

    Credits

    Thanks to our 1 contributor whose commits are featured in this release: @johnashu

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Dec 11, 2019)

Owner
Maciej J Mikulski
Maciej J Mikulski
WindowsDebloat - Windows Debloat with python

Windows Debloat 🗑️ Quickly and easily configure Windows 10. Disclaimer I am NOT

1 Mar 26, 2022
Small Python script to parse endlessh's output and print some neat statistics

endlessh_parser endlessh_parser is a small Python script that parses endlessh's output and prints some neat statistics about it Usage Install all the

ManicRobot 1 Oct 18, 2021
Package that allows for validate and sanitize of string values.

py.validator A library of string validators and sanitizers Insipired by validator.js Strings only This library validates and sanitizes strings only. P

Sanel Hadzini 22 Nov 08, 2022
A python app which aggregates and splits costs from multiple public cloud providers into a csv

Cloud Billing This project aggregates the costs public cloud resources by accounts, services and tags by importing the invoices from public cloud prov

1 Oct 04, 2022
Runes - Simple Cookies You Can Extend (similar to Macaroons)

Runes - Simple Cookies You Can Extend (similar to Macaroons) is a paper called "Macaroons: Cookies with Context

Rusty Russell 22 Dec 11, 2022
A multipurpose python module

pysherlock pysherlock is a Python library for dealing with web scraping using images, it's a Python application of the rendertron headless browser API

Sachit 2 Nov 11, 2021
🚧Useful shortcuts for simple task on windows

Windows Manager A tool containg useful utilities for performing simple shortcut tasks on Windows 10 OS. Features Lit Up - Turns up screen brightness t

Olawale Oyeyipo 0 Mar 24, 2022
✨ Voici un code en Python par moi, et en français qui permet d'exécuter du Javascript en Python.

JavaScript In Python ❗ Voici un code en Python par moi, et en français qui permet d'exécuter du Javascript en Python. 🔮 Une vidéo pour vous expliquer

MrGabin 4 Mar 28, 2022
The Black shade analyser and comparison tool.

diff-shades The Black shade analyser and comparison tool. AKA Richard's personal take at a better black-primer (by stealing ideas from mypy-primer) :p

Richard Si 10 Apr 29, 2022
A (very dirty) experiment to remove layers from a Docker image.

Surgically remove layers from a Docker image (with a chainsaw)

JĂ©rĂ´me Petazzoni 9 Jun 08, 2022
jfc is an utility to make reviewing ArXiv papers for your Journal Club easier.

jfc is an utility to make reviewing ArXiv papers for your Journal Club easier.

Miguel M. 3 Dec 20, 2021
A program to convert celcius to faranheit. made with python

Temp-Converter What is Temp-Converter Temp-Converter is little program made with pyhton to convert celcius to faranheit. Needed A python interpreter P

Chandula Janith 0 Nov 27, 2021
✨ Un code pour voir les disponibilités des vaccins contre le covid totalement fait en Python par moi, et en français.

Vaccine Notifier ❗ Un chois aléatoire d'un article sur Wikipedia totalement fait en Python par moi, et en français. 🔮 Grâce a une requète API, on peu

MrGabin 3 Jun 06, 2021
Automatically Generate Rulesets for IIS for Intelligent HTTP/S C2 Redirection

Automatically Generate Rulesets for IIS for Intelligent HTTP/S C2 Redirection This project converts a Cobalt Strike profile to a functional web.config

Jesse 99 Dec 13, 2022
Yet another retry utility in Python

Yet another retry utility in Python, avereno being the Malagasy word for retry.

Haute École d'Informatique de Madagascar 4 Nov 02, 2021
EVE-NG tools, A Utility to make operations with EVE-NG more friendly.

EVE-NG tools, A Utility to make operations with EVE-NG more friendly. Also it support different snapshot operations with same style as Libvirt/KVM

Bassem Aly 8 Jan 05, 2023
Use generator for range function

Use the generator for the range function! installation method: pip install yrange How to use: First import yrange in your application. You can then wo

1 Oct 28, 2021
✨ Un pierre feuille ciseaux totalement fait en Python par moi, et en français.

Pierre Feuille Ciseaux âť— Un pierre feuille ciseaux totalement fait en Python par moi. đź”® Avec l'utilisation du module "random", j'ai pu faire un choix

MrGabin 3 Jun 06, 2021
Simple yet flexible natural sorting in Python.

natsort Simple yet flexible natural sorting in Python. Source Code: https://github.com/SethMMorton/natsort Downloads: https://pypi.org/project/natsort

Seth Morton 712 Dec 23, 2022
A python program to find binary, octal and hexadecimal of a decimal.

decimal-converter This little python program can convert a decimal in to, Binary Octal Hexadecimal Needed Python 3 or later or a online python compile

Chandula Janith 0 Nov 27, 2021