Skip to main content

painless-timeit

A timeit decorator for Python functions that allows for splits measurements inside of the function without the hustles of modifying too much code after performance analysis

Usage

Apply @painless_timeit decorator to your function and it will be timed as usual, printing the measured time at the end of its execution. If you want to also measure timesplits inside your function you can add the comment #|> [split_name] before the code block you want to time and #|| [split_name] after. The wrapper function keeps a record of each split with its current measured time, meaning that multiple references to the same split will accumulate. You can also pause time measurements for the function by commenting #|| and resume it with #|>. The wrapper function will replace the lines with these kind of comments with the needed code, so be sure to place these comments in dedicated lines, or else you may not execute important pieces of code.

Here's an example of a decorated function and its execution:

from painless_timeit import painless_timeit

@painless_timeit
def my_function():
    #|> split1
    time.sleep(2) # code in this block will be measured as split1
    #|| split1
    #|> split2
    time.sleep(0.5) # code in this block will be measured as split2
    #|| split2
    #||
    time.sleep(10) # code in this block won't be measured
    #|>
    time.sleep(1) # code in this block will be measured as the main function

Output:

>>> my_function()
[my_function->split1]: Took 2.0000 seconds up until now
[my_function->split2]: Took 0.5000 seconds up until now
[my_function]: Took 3.5000 seconds

Note

The choice for the symbols used for the signal comments will be clear if you use Fira Code font with ligatures

Metadata

Release files for painless-timeit 0.0.1

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

Source distribution (sdist)

Source distribution for painless-timeit 0.0.1
File Size Uploaded Provenance Actions
painless_timeit-0.0.1.tar.gz 4.7 kB Without provenance Details for painless_timeit-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for painless-timeit 0.0.1
File Interpreter ABI Platform Actions
painless_timeit-0.0.1-py3-none-any.whl Python 3 none any Details for painless_timeit-0.0.1-py3-none-any.whl

Total release size: 9.0 kB

Release files / painless_timeit-0.0.1.tar.gz

Download URL painless_timeit-0.0.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c09b9ad794dd7031c9cf8062902b84ede717d85506f31d456665213df1f3f604
BLAKE2b-256 checksum
How to use checksums
be0ceabb92f26ea37f39806dadd41778d6d4464cf5309be84dcafbc9405218bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.0

Release files / painless_timeit-0.0.1-py3-none-any.whl

Download URL painless_timeit-0.0.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25219f0ac3cc43d4c9218acb9b4a5855887c16ba2f97e8378b03fde4e8964c55
BLAKE2b-256 checksum
How to use checksums
46af419fa06912ab54c220bc14d65c44ac65bbc2817b021d25f902ea174602e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.0

Security for painless-timeit 0.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.0.1 This release

2 release files No 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