Skip to main content

PyPi License CodeFactor Repository size made-with-python

Timer

An easy to use python package to handle time measurements in code.

Instantiate the Timer class and insert one-liners with take_time() between your existing code to take timestamps.

Call the fancy_print() function to print a nicely formatted overview of how much time has passed overall, how much time has passed between the take_time() calls, including percentage per step and passed step-descriptions.

Installation

The package is available on PyPi :

pip install quicktimer 

Usage

The entire functionality is documented in-depth on readthedocs. In the following a quick overview of the basic functionality is shown.

The two main commands are take_time() and fancy_print().

Both can be used without any parameters, although you should pass at least a description to take_time("Finished_x!") to add some context to your measurements.

You can either make use of the default output method (print to the console) or you can pass a custom function: for instance to pass the messages to a logger.

Using the default output method (print)

When no output_func parameter is passed during instantiation, it defaults to print the messages to the console as follows:

import time
from quicktimer import Timer

T = Timer()

# take the starting time
T.take_time(description="The description of the first function-call is not displayed!")

time.sleep(1.1)  # code substitute: parsing the data
T.take_time("Parsed the data")

time.sleep(0.02)  # code substitute
T.take_time() 

time.sleep(0.1) # code substitute: Storing the data
T.take_time("Stored the data", True)

T.fancy_print()

Output of the code in the console:

> Stored the data
> ------ Time measurements ------
> Overall: 0:00:01.254049
> Step 0: 0:00:01.113962 -  88.83 % - Description: Parsed the data
> Step 1: 0:00:00.030001 -   2.39 % - Description: 
> Step 2: 0:00:00.110086 -   8.78 % - Description: Stored the data

Using a logger as output method

Instead of printing to the console, you can also pass your own function to the module. This can be used with an easily configured logger to write the messages to your log.

import time
import logging
from quicktimer import Timer

# setting up a logger
my_format = "%(asctime)s [%(levelname)-5.5s]  %(message)s"
logging.basicConfig(filename='test.log', level=logging.INFO, format=my_format)
logger = logging.getLogger()

# logger.info will be used as the output function instead of print
T = Timer(output_func=logger.info)  

T.take_time()  # take the starting time
time.sleep(0.5)  # code substitute: parsing the data
T.take_time("Parsed the data")
time.sleep(0.1)  # code substitute: Storing the data
T.take_time("Stored the data", True)

T.fancy_print()

Your log would look like this:

2021-06-24 13:35:43,275 [INFO ]  Stored the data
2021-06-24 13:35:43,275 [INFO ]  ------ Time measurements ------
2021-06-24 13:35:43,275 [INFO ]  Overall: 0:00:00.624691
2021-06-24 13:35:43,275 [INFO ]  Step 0: 0:00:00.512639 -  82.06 % - Description: Parsed the data
2021-06-24 13:35:43,275 [INFO ]  Step 1: 0:00:00.112052 -  17.94 % - Description: Stored the data

Metadata

Release files for quicktimer 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quicktimer 0.2.0
File Size Uploaded Provenance Actions
quicktimer-0.2.0.tar.gz 6.2 kB Without provenance Details for quicktimer-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quicktimer 0.2.0
File Interpreter ABI Platform Actions
quicktimer-0.2.0-py3-none-any.whl Python 3 none any Details for quicktimer-0.2.0-py3-none-any.whl

Total release size: 12.2 kB

Release files / quicktimer-0.2.0.tar.gz

Download URL quicktimer-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
57c67ae359a6a3ce17ce14ec41de729b0521d2759781512b5f9246e0e6dbe97e
BLAKE2b-256 checksum
How to use checksums
555b3f9bbd640dc6a22c246eb21f3ff67e008b165a809600f4338460a5864297
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release files / quicktimer-0.2.0-py3-none-any.whl

Download URL quicktimer-0.2.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2691aa2b1e85ae784b91d51b6dc563b0865bd8620866aecce3eee8226efc2f38
BLAKE2b-256 checksum
How to use checksums
d21c528cd35d66ca799afb0e89f49e8bd68017c5b662127c0c7da526ec8e1398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Security for quicktimer 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page