Skip to main content

Latest version Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 | 3.15+ MIT license Codecov CodeQL Test Downloads

⏳ Timer for Python ⌛️

Lightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code.

Ready to try? Learn how to install and find tutorials in the user guide.

Getting Started

Basics

Simply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:

from timer import Timer

timer = Timer()
timer.start()

# Insert your code here

timer.stop()  # Output example: 12.34 seconds

Context Manager

Alternatively, use the with statement. This will automatically start and stop the clock – and so no need to declare timer.start() and timer.stop(). Same result as before, but less code:

with Timer():
    # Insert your code here

    # Output example: 12.34 seconds

Decorator

Or use the function_timer as a function decorator:

from timer import function_timer

@function_timer()
def test_function():
    # Insert your code here

test_function()

# Output example: 12.34 seconds for thread TEST_FUNCTION

Core Features

Decimals

Instead of the default value of 2 for decimals``, you can set the output precision up to 9in thedecimals` parameter:

timer = Timer()
timer.start(decimals=5)

# Insert your code here

timer.stop()  # Output example: 0.12345 seconds

Multiple Threads

Imagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.

To measure the performance of multiple blocks of code, use the thread parameter to name different threads:

timer = Timer()
timer.start(thread="A")

# Insert your code here

    timer.start(thread="B", decimals=5)

    # Insert more code here

    timer.stop(thread="B") # Output example: 0.12345 seconds for thread B

# Insert even more code here

timer.stop(thread="A") # Output example: 6.78 seconds for thread A

Or use the with statement to get the same result with less code:

with Timer(thread="A")
    # Insert your code here

    with Timer(thread="B", decimals=5):
        # Insert more code here

        # Output example: 0.12345 seconds for thread B

    # Insert even more code here

    # Output example: 6.78 seconds for thread A

Become a Sponsor 🏅

If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution makes a difference, whether you buy a coffee or support with a monthly donation. Find your tier here:

Donate on GitHub Sponsors

Thank you for your support! 🙌

Contribute

If you have suggestions or changes to the module, feel free to add to the code and create a pull request.

Report Bugs

If you encounter any issues, you can report them as bugs or raise issues.

Metadata

Release files for timer-for-python 0.9.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timer-for-python 0.9.13
File Size Uploaded Provenance Actions
timer_for_python-0.9.13.tar.gz 10.9 kB With provenance Details for timer_for_python-0.9.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for timer-for-python 0.9.13
File Interpreter ABI Platform Actions
timer_for_python-0.9.13-py3-none-any.whl Python 3 none any Details for timer_for_python-0.9.13-py3-none-any.whl

Total release size: 26.5 kB

Release files / timer_for_python-0.9.13.tar.gz

Download URL timer_for_python-0.9.13.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1ffc113cd2f66fbbb21e40e07284263542c9071234f857734a39eed38be19c4b
BLAKE2b-256 checksum
How to use checksums
e6bc90f9262d89e99002dc99db159ae235165cabd82c9b845c1901acbacdb628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / timer_for_python-0.9.13-py3-none-any.whl

Download URL timer_for_python-0.9.13-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f5a09da107c9f5e95998eb69375a8700934adf38256e61e77dd0bea6014e8e3
BLAKE2b-256 checksum
How to use checksums
01eef21b3f32457eba806d3654c80f64364b97d84570393bcbb78ae987e046de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for timer-for-python 0.9.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for timer_for_python-0.9.13.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.13 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page