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
Keval allows you to call arbitrary Windows kernel-mode functions from user mode, even (and primarily) on another machine.

Keval Keval allows you to call arbitrary Windows kernel-mode functions from user mode, even (and primarily) on another machine. The user mode portion

42 Dec 17, 2022
API for obtaining results from the Beery-Bukenica test of the visomotor integration development (VMI) 4th edition.

VMI API API for obtaining results from the Beery-Bukenica test of the visomotor integration development (VMI) 4th edition. Install docker-compose up -

Victor Vargas Sandoval 1 Oct 26, 2021
A library to easily convert climbing route grades between different grading systems.

pyclimb A library to easily convert climbing route grades between different grading systems. In rock climbing, mountaineering, and other climbing disc

Ilias Antonopoulos 4 Jan 26, 2022
New time-based UUID formats which are suited for use as a database key

uuid6 New time-based UUID formats which are suited for use as a database key. This module extends immutable UUID objects (the UUID class) with the fun

26 Dec 30, 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
Backup a folder to an another folder by using mirror update method.

Mirror Update Backup Backup a folder to an another folder by using mirror update method. How to use Install requirement pip install -r requirements.tx

1 Nov 21, 2022
A toolkit for writing and executing automation scripts for Final Fantasy XIV

XIV Scripter This is a tool for scripting out series of actions in FFXIV. It allows for custom actions to be defined in config.yaml as well as custom

Jacob Beel 1 Dec 09, 2021
Tools for binary data on cassette

Micro Manchester Tape Storage Tools for storing binary data on cassette Includes: Python script for encoding Arduino sketch for decoding Eagle CAD fil

Zack Nelson 28 Dec 25, 2022
A workflow management tool for numerical models on the NCI computing systems

Payu Payu is a climate model workflow management tool for supercomputing environments. Payu is currently only configured for use on computing clusters

The Payu Organization 11 Aug 25, 2022
Python type-checker written in Rust

pravda Python type-checker written in Rust Features Fully typed with annotations and checked with mypy, PEP561 compatible Add yours! Installation pip

wemake.services 31 Oct 21, 2022
Lock files using python and cmd

Python_Lock_Files Lock files using python and cmd license feel free to do whatever you want to with these files, i dont take any responsibility tho, u

1 Nov 01, 2021
VerSign: Easy Signature Verification in Python

VerSign: Easy Signature Verification in Python versign is a small Python package which can be used to perform verification of offline signatures. It a

Muhammad Saif Ullah Khan 3 Dec 01, 2022
An okayish python script to generate a random Euler circuit with given number of vertices and edges.

Euler-Circuit-Test-Case-Generator An okayish python script to generate a random Euler circuit with given number of vertices and edges. Executing the S

Alen Antony 1 Nov 13, 2021
This is Cool Utility tools that you can use in python.

This is Cool Utility tools that you can use in python. There are a few tools that you might find very useful, you can use this on pretty much any project and some utils might help you a lot and save

Senarc Studios 6 Apr 18, 2022
Python lightweight dependency injection library

pythondi pythondi is a lightweight dependency injection library for python Support both sync and async functions Installation pip3 install pythondi Us

Hide 41 Dec 16, 2022
Create password - Generate Random Password with Passphrase

Generate Random Password with Passphrase This is a python code to generate stron

1 Jan 18, 2022
Collection of code auto-generation utility scripts for the Horizon `Boot` system module

boot-scripts This is a collection of code auto-generation utility scripts for the Horizon Boot system module, intended for use in Atmosphère. Usage Us

4 Oct 11, 2022
MITRE ATT&CK Lookup Tool

MITRE ATT&CK Lookup Tool attack-lookup is a tool that lets you easily check what Tactic, Technique, or Sub-technique ID maps to what name, and vice ve

Curated Intel 33 Nov 22, 2022
Adding two matrix from scratch using python.

Adding-two-matrix-from-scratch-using-python. Here, I have take two matrix from user and add it without using any library. I made this program from scr

Sachin Vinayak Dabhade 4 Sep 24, 2021
Simple collection of GTPS Flood in Python.

GTPS Flood Simple collection of GTPS Flood in Python. NOTE Give me credit if you use this source, don't trade/sell this tool, And USE AT YOUR OWN RISK

PhynX 6 Dec 07, 2021