Skip to main content

Easy and accurate timer for Python.

Project description

timer.py

timer.py provides convenient functions to measure time in Python.

Installation

pip install timer.py

Usage

from time import sleep
from timer_py import Timer

timer = Timer()
timer.start()
# Or:
# timer = Timer(start=True)

# A one-second process
sleep(1)

# Printing the elapsed time. The timer will continue to run.
timer.elapsed()
# Output:
# [timer.py] 00:00:01.001

timer.pause()

# A one-second process that won't be counted while the timer is paused.
sleep(1)

timer.resume()

# Another one-second process.
sleep(1)

# Overriding the tag for one time only (the original tag will still be remembered).
timer.elapsed('Checkpoint 1')
# Output:
# [Checkpoint 1] 00:00:02.002

timer.set_tag('Custom title')

timer.restart()

# Another one-second process.
sleep(1)

# Storing the elapsed time to a variable as a float while hiding the output.
elapsed = timer.elapsed(print=False)
print(elapsed)
# Output:
# 00:00:01.001

timer.stop()
# Output:
# [Custom title] 00:00:01.001

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

timer.py-2.4.0.tar.gz (15.0 kB view hashes)

Uploaded source

Built Distribution

timer.py-2.4.0-py3-none-any.whl (16.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page