Skip to main content

Timing class for measuring elapsed time and average elapsed time.

Project description

noiftimer

Simple timer class to track elapsed time.
Install with:

pip install noiftimer

Usage:

from noiftimer import Timer, time_it, log_time
import time

Timer object:

>>> def very_complicated_function():
...     time.sleep(1)
...
>>> timer = Timer()
>>> for _ in range(10):
...     timer.start()
...     very_complicated_function()
...     timer.stop()
...
>>> print(timer.stats)
elapsed time: 1s 1ms 173us
average elapsed time: 1s 912us
>>> timer.elapsed
1.001173496246338
>>> timer.elapsed_str
'1s 1ms 173us'
>>> timer.average_elapsed
1.0009121656417848
>>> timer.average_elapsed_str
'1s 912us'

time_it decorator (executes the decorated function 10 times)

>>> @time_it(10)
... def very_complicated_function():
...     time.sleep(1)
...
>>> very_complicated_function()
very_complicated_function average execution time: 1s 469us

Alternatively, the log_time decorator can be used to instead log the execution time to a file.

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

noiftimer-2.5.0.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.

noiftimer-2.5.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file noiftimer-2.5.0.tar.gz.

File metadata

  • Download URL: noiftimer-2.5.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for noiftimer-2.5.0.tar.gz
Algorithm Hash digest
SHA256 1ec7311aa79ccc5f85b3d1d7b822122b3a7fa7f56ea4229ed0c8fd7fafecadcc
MD5 313200977c14d028b69a9d1c17bbe02b
BLAKE2b-256 30f320bb6c096478354af0308d6ca693d5aa34364d04e7bcc858ce6b5344216f

See more details on using hashes here.

File details

Details for the file noiftimer-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: noiftimer-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for noiftimer-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ec34e7826a0008a29ff67ed62fe547d88f2146acddf5924a0283aa4177b01e4
MD5 6b1f1921aba0d7abc76839afb0e359cb
BLAKE2b-256 9bc0ace39a12a2d80fb5f45e5af1899b21c725fdc83f215d9d077addec18a931

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