Context manager for measuring execution times
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
timethis-0.1.2.tar.gz
(2.7 kB
view details)
Built Distribution
File details
Details for the file timethis-0.1.2.tar.gz
.
File metadata
- Download URL: timethis-0.1.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0da79fb6b89a1ed9301a504d482da17abb39ade8f586d058189f89a18016c674 |
|
MD5 | b79c601f50b9949b9ce89598037680ca |
|
BLAKE2b-256 | e00bebe949cfd5cf02d99394d4e05f91ff2b5b4c6d3c4cb34fd117909f26fdf4 |
File details
Details for the file timethis-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: timethis-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac55530f765ac7a50c7baf68a4108fa7221f88a14a62556447d0be1255cb5c4 |
|
MD5 | ae6e35182be59284a60a108941daf7f8 |
|
BLAKE2b-256 | 7a48cbd384059ad448fc73f2aa8b6348e368d2889bd94bf5493aae6baa2d780c |