Skip to main content

Small tool to track time of Python code blocks.

Project description

Coverage Maintenance PyPI version PyPI pyversions PyPI status

about-time

Small tool to track time of Python code blocks.

What does it do?

There are several times we need to instrument and log code execution, to see where complex pipelines are spending the most time in.

A simple start = time.time() and end = time.time() - start does not cut it when we want to track several lines at the same time, and/or whole blocks with line granularity.

How to use it?

The tool supports being used like a context manager or a callable handler.

Like this:

from about_time import about_time

with about_time() as t_whole:
    with about_time() as t_1:
        func_1()
    with about_time() as t_2:
        func_2('params')

Then, get the timings like this:

print(f'func_1 time: {t_1.duration_human}')
print(f'func_2 time: {t_2.duration_human}')
print(f'total time: {t_whole.duration_human}')

There's also the duration property, which returns the actual float time in seconds.

You can also use it like:

t = about_time(func_1)
t = about_time(lambda: func_2('params'))

Or you mix and match both:

with about_time() as t_whole:
    t_1 = about_time(func_1)
    t_2 = about_time(lambda: func_2('params'))

How do I install it?

$ pip install about-time

License

This software is licensed under the MIT License. See the LICENSE file in the top distribution directory for the full license text.

Nice huh?

Thanks for your interest!

I wish you have fun using this tool! :)

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

about-time-1.0.0.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

about_time-1.0.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page