sProfiler
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sprofiler-0.1.0.tar.gz | 3.5 kB | Without provenance | Details for sprofiler-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sprofiler-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sprofiler-0.1.0-py3-none-any.whl |
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
|
Security for sprofiler 0.1.0
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.