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)
| File | Size | Uploaded | |
|---|---|---|---|
| painless_timeit-0.0.1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| painless_timeit-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
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
|