Skip to main content

sProfiler

PyPI version

Python script profiler/timer supporting code checkpoints and reporting.

Installation

pip install sprofiler

Usage

Use the Profiler to create named checkpoints throughout your code. Checkpoints need a 'start' and a 'stop', and multiple iterations are combined to summarize how long it takes to complete each leg. The report() function prints the results from all checkpoints.

import sprofiler as sp
from time import sleep

pr = sp.Profiler()

pr.start('program')
print('Code outside loop')
sleep(1)

for _ in range(10):
    pr.start('sleep_1s')
    print('Code in loop')
    sleep(1)
    pr.stop('sleep_1s')
pr.stop('program')

pr.report()

The printed report appears as:

program | 11.0 s ± 0.0 s per iteration, n = 1
sleep_1s | 1.0 s ± 0.0 s per iteration, n = 10

Logging

sProfiler automatically logs results by default. You can change the destination filename, as well as the level of verbosity: 0 - no logging, 1 - only elapsed times, 2 - start and stop times. Defaults are logname='profiler.log' and verbose=2.

import sprofiler as sp
from time import sleep

pr = sp.Profiler(logname='my_log.log', verbose=1)

Function Decorators

sProfiler also supports timing functions with decorators, via Profiler.time_func. Demonstrating on the first example:

pr = sp.Profiler()

@pr.time_func
def sleep_1s():
    print('Code in loop')
    sleep(1)

@pr.time_func
def my_func():
    for _ in range(10):
        sleep_1s()

pr.report()

The printed report appears as:

my_func | 10.0 s ± 0.0 s per iteration, n = 1
sleep_1s | 1.0 s ± 0.0 s per iteration, n = 10

Future Directions

  • Potential support for more complex profiling

Metadata

Release files for sprofiler 0.1.0

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

Source distribution (sdist)

Source distribution for sprofiler 0.1.0
File Size Uploaded
sprofiler-0.1.0.tar.gz 3.5 kB Details

Built distribution (wheel)

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

Total release size: 8.4 kB

Release files / sprofiler-0.1.0.tar.gz

Download URL sprofiler-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
abae3c356cbe107d5eb1972dc24270ca24f0d14454fc2f2148fc44bf445d1a33
BLAKE2b-256 checksum
How to use checksums
467ddc203f4747939ee2ad7ccd3ea80349e15f4657de4096df70dc58b5eec490
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.10

Release files / sprofiler-0.1.0-py3-none-any.whl

Download URL sprofiler-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fad413920f85edb5b3296ced7aeada086f9d91bb91b295c089de6daf3168f730
BLAKE2b-256 checksum
How to use checksums
600a81f95988f54f64558f2422128668df5d4377faeeb3f63bee9a068545cb51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

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