Yet another way to measure code execution duration using a context
Project description
context-timing
A python context manager for timing of a block. Somewhat similar to contexttimer or timethis.
Uses perf_counter_ns()
underneath.
The goal of this package is not to be extremely accurate or lightweight. Though both should be acceptable.
Use case
Main use case
This package is not intended to measure perfomance like timeit would do. The main use case here is to get a quick way to display how long a block of code takes to execute. For instance if you have a large amount of code that runs, and have a feeling that the duration of some functions could help you understand the behaviour. This package lets you easily add a display of this timing.
How to use
Basic
from context_timing import measure_time
with measure_time():
sleep(1)
Set output steam for multiple calls
from context_timing import measure_time, set_log_func
set_log_func(print)
with measure_time():
sleep(1)
with measure_time():
sleep(2)
Redirect the output for one measurement
import logging
from context_timing import measure_time, set_log_func
set_log_func(print)
with measure_time(logging.info):
sleep(1)
with measure_time():
sleep(2)
In-between timing
The package, similarly to contexttimer
lets you get the time since start, within the context.
from context_timing import measure_time
with measure_time() as m:
sleep(1)
m.print() # ~1s
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
Built Distribution
File details
Details for the file context_timing-0.0.2.tar.gz
.
File metadata
- Download URL: context_timing-0.0.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2a036f45eec6f87761f3d480039ab807f7cc977683ab2f4334cff37867cc1e |
|
MD5 | 0bb9a803e79ceaefc41bd77f9189b7d7 |
|
BLAKE2b-256 | 137386a3a9812fa08879654a1d0954fed5527bacc2c11ee2571b07de9a74369a |
File details
Details for the file context_timing-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: context_timing-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e3941088d01cff57e019970c20a00d7e210a0f8b2849d54c673aad74c0829db |
|
MD5 | 39b6d58c6b2d49e76bd34e2608627f62 |
|
BLAKE2b-256 | 5133454f58e60ee834a67bb074b45b84a3d74550ada3fbd7847586be9a9f3fe3 |