Skip to main content

A timeit decorator with built-in split functionality for Python

Project description

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

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

painless_timeit-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

painless_timeit-0.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file painless_timeit-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for painless_timeit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c09b9ad794dd7031c9cf8062902b84ede717d85506f31d456665213df1f3f604
MD5 2ef0a7a4dcdea9dd8621f35fa12f2e27
BLAKE2b-256 be0ceabb92f26ea37f39806dadd41778d6d4464cf5309be84dcafbc9405218bc

See more details on using hashes here.

File details

Details for the file painless_timeit-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for painless_timeit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 25219f0ac3cc43d4c9218acb9b4a5855887c16ba2f97e8378b03fde4e8964c55
MD5 aff2f534184e4846260350ec3de96c91
BLAKE2b-256 46af419fa06912ab54c220bc14d65c44ac65bbc2817b021d25f902ea174602e7

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