Skip to main content

This module provides a context manager for measuring execution times:

>>> from timethis import timethis
>>> with timethis('computing large sum'):
...     x = sum(range(10**7))
...
computing large sum: 0.203 seconds

Usage of timethis can be nested:

>>> with timethis('figuring things out'):
...     with timethis('computing large sum'):
...         x = sum(range(10**7))
...     with timethis('finding some primes'):
...         y = [2] + [i for i in range(3, 10**4) if all(i % j != 0 for j in range(2, i // 2 + 1))]
...
│ computing large sum: 0.205 seconds
│ finding some primes: 0.305 seconds
figuring things out: 0.510 seconds

It's easy to use (for example) logging instead of print:

>>> import logging
>>> with timethis('computing large sum', logging.warning):
...     x = sum(range(10**7))
...
WARNING:root:computing large sum: 0.218 seconds

Metadata

Release files for timethis 0.1.2

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

Source distribution (sdist)

Source distribution for timethis 0.1.2
File Size Uploaded
timethis-0.1.2.tar.gz 2.7 kB Details

Built distribution (wheel)

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

Total release size: 5.7 kB

Release files / timethis-0.1.2.tar.gz

Download URL timethis-0.1.2.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0da79fb6b89a1ed9301a504d482da17abb39ade8f586d058189f89a18016c674
BLAKE2b-256 checksum
How to use checksums
e00bebe949cfd5cf02d99394d4e05f91ff2b5b4c6d3c4cb34fd117909f26fdf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.7

Release files / timethis-0.1.2-py3-none-any.whl

Download URL timethis-0.1.2-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ac55530f765ac7a50c7baf68a4108fa7221f88a14a62556447d0be1255cb5c4
BLAKE2b-256 checksum
How to use checksums
7a48cbd384059ad448fc73f2aa8b6348e368d2889bd94bf5493aae6baa2d780c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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