Skip to main content

BuildBadge PyPIVersion PythonFormat

ptimeit

pretty timeit - simple and pretty python code profiler for measuring execution time

pip install ptimeit

examples

function execution time

use timeit_function decorator for measuring function execution time

import time
from ptimeit import timeit_function


@timeit_function('foo')
def foo():
    time.sleep(0.1)


foo()

outputs:

->>>>>>>>         102.7ms      foo()

Adding a conditional function that determines if something is printed. The function receives elapsed time in milliseconds as an input and is expected to return a boolean.

import time
from ptimeit import timeit_function


@timeit_function('foo', lambda t: t > 500)
def foo():
    time.sleep(0.1)

@timeit_function('bar', condition=lambda t: t > 500)
def bar():
    time.sleep(1)

foo()
bar()

No output for foo - measured time needs to be over 500ms to be printed.

bar outputs:

->>>>>>>>        1003.1ms      bar()

Adding extra data

import time
from ptimeit import timeit_function


@timeit_function('foo', extra_data_to_print="This is a string")
def foo():
    time.sleep(0.1)


foo()

outputs:

->>>>>>>>         103.3ms      foo() - This is a string

code section execution time

use timeit_section context manager for measuring code section execution time

import time
from ptimeit import timeit_section

with timeit_section('bar'):
     time.sleep(0.1)

outputs:

->>>>>>>>         105.1ms      bar

It is also possible to use conditional condition function and extra_data_to_print the same way as in timeit_function.


nested mixture of functions and sections

import time
from ptimeit import timeit_function, timeit_section


@timeit_function('foo_inner')
def foo_inner():
    with timeit_section('foo_inner:section_1'):
        time.sleep(0.05)
    with timeit_section('foo_inner:section_2'):
        time.sleep(0.25)


@timeit_function('foo_outer')
def foo_outer():
    with timeit_section('foo_outer:section_1'):
        time.sleep(0.2)

    foo_inner()

    with timeit_section('foo_outer:section_2'):
        time.sleep(0.4)


with timeit_section('bar:outer'):
    foo_outer()
    time.sleep(0.1)

outputs:

->>>>>>>>         200.1ms      |   |   foo_outer:section_1
->>>>>>>>          51.3ms      |   |   |   foo_inner:section_1
->>>>>>>>         252.8ms      |   |   |   foo_inner:section_2
->>>>>>>>         304.3ms      |   |   foo_inner()
->>>>>>>>         403.0ms      |   |   foo_outer:section_2
->>>>>>>>         907.6ms      |   foo_outer()
->>>>>>>>        1010.8ms      bar:outer

Metadata

Release files for ptimeit 0.1.2

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

Source distribution (sdist)

Source distribution for ptimeit 0.1.2
File Size Uploaded Provenance Actions
ptimeit-0.1.2.tar.gz 3.4 kB Without provenance Details for ptimeit-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ptimeit 0.1.2
File Interpreter ABI Platform Actions
ptimeit-0.1.2-py3-none-any.whl Python 3 none any Details for ptimeit-0.1.2-py3-none-any.whl

Total release size: 7.4 kB

Release files / ptimeit-0.1.2.tar.gz

Download URL ptimeit-0.1.2.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
876a337c9a486f708676aca3392af02df4d0d6acc219fe4240142d1caacc8f06
BLAKE2b-256 checksum
How to use checksums
4b1eb240f5ba397dbdfc6be6a6a81911ab9507b81d040fc1755303ca970f6db4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / ptimeit-0.1.2-py3-none-any.whl

Download URL ptimeit-0.1.2-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
658ab40e3461fcbe006888f7987e9c190c0bf8d31986c0efad6a91b0f63848bd
BLAKE2b-256 checksum
How to use checksums
6647119f624cf80ff9d5aefed5221660b4233e13ba19577722804d801f636206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for ptimeit 0.1.2

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.

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