Skip to main content

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_timing-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

context_timing-0.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file context_timing-0.0.1.tar.gz.

File metadata

  • Download URL: context_timing-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for context_timing-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5b1fc58066b342389b8790bc726d97246a0f51761de0ccab309c21059225564c
MD5 4d5e3be01bf6359a41c9e029a470c10e
BLAKE2b-256 091ee9498a2057ae4d8e0a73b77b890e4f99560e04a093f17c2c18a076264192

See more details on using hashes here.

File details

Details for the file context_timing-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: context_timing-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for context_timing-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a1e91668b08875e6f8f7ab415a0cd181c5113bdf143d4b2c1190f560009a3a23
MD5 7c2287b5900e4995e34d26f5dcd5922a
BLAKE2b-256 06882479333fc6f17f7761679756053bf736b57261b71c58e28c7c971b512778

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page