Skip to main content

Measure execution time of any function

Project description

philiprehberger-timerfunc

Tests PyPI version License

Measure execution time of any function.

Installation

pip install philiprehberger-timerfunc

Usage

Context Manager

from philiprehberger_timerfunc import timer

with timer() as t:
    do_work()
print(f"Took {t.elapsed_ms:.1f}ms")

Decorator

from philiprehberger_timerfunc import timed

@timed
def process_data():
    ...  # logs: "process_data took 42.3ms"

@timed(threshold_ms=100)
def api_call():
    ...  # only logs if slower than 100ms

Benchmark

from philiprehberger_timerfunc import benchmark

result = benchmark(my_function, args=(data,), iterations=1000)
print(f"Mean: {result.mean_ms:.2f}ms, P95: {result.p95_ms:.2f}ms")
print(result)  # full stats summary

API

  • timer() — Context manager returning TimerResult
  • @timed / @timed(threshold_ms=0) — Decorator logging execution time
  • benchmark(fn, args, kwargs, iterations, warmup) — Returns BenchmarkResult

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

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

Source Distribution

philiprehberger_timerfunc-0.1.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_timerfunc-0.1.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_timerfunc-0.1.4.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_timerfunc-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8e12d144ebba40f3935e8fd5630460e56e4104fdf589b5860a62d7542fdb7543
MD5 289e9b97d40758d9f07968d7b566e5e2
BLAKE2b-256 3135c696a32ceca86ff3fe396cabd60b7c4ad7c920ff85fd1ca47b5d8060a333

See more details on using hashes here.

File details

Details for the file philiprehberger_timerfunc-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_timerfunc-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d56cdbcb1ff915e4c2d951bb9509904fdd8cafd1890d051d333487ff9020514f
MD5 01ee08b6c7adeab8d42c67bd14029b43
BLAKE2b-256 0d021ea807e6a8bdd7f564960fa419d6286b30b71e229dab2c6a2fbf3a46cf6b

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 Pingdom Monitoring Sentry Error logging StatusPage Status page