Skip to main content

A very simple profiler for Python.

Project description

SiPro

Nothing to see here...

...just a very simple python profiler

Examples

With context manager

Code

# Use default profiler
from sipro import default_profiler as profiler

# Create your own profiler
from sipro import Profiler

my_profiler = Profiler()

with profiler('my loop'):
    for i in range(1000):
        pass

with profiler('nested parent'):
    for i in range(50):
        pass

    with profiler('nested child 1'):
        for i in range(50):
            pass

    with profiler('nested child 2'):
        for i in range(50):
            pass

print(profiler)

Output

100.0% (100.0%)
my loop:       37.4% (37.4%)
nested parent: 17.6% (17.6%)
  nested child 1: 14.5% (2.5%)
  nested child 2: 11.3% (2.0%)
  ...:            74.2% (13.0%)
...:           45.0% (45.0%)

With functions

Code

from sipro import default_profiler as profiler


@profiler.wrap
def inherit_name():
    for i in range(1000):
        pass

from functools import partial

@partial(profiler.wrap, name='custom_name')
def dont_use_fn_name():
    for i in range(1000):
        pass

    # Functions also nest properly
    inherit_name()

dont_use_fn_name()

print(profiler)

Output

100.0% (100.0%)
custom_name: 71.4% (71.4%)
  inherit_name: 42.2% (30.1%)
  ...:          57.8% (41.3%)
...:         28.6% (28.6%)

Output

There are two ways of getting the output:

  1. Cast to string str(profiler) - Output same as above
  2. Get dict, by profiler.dict() - Structure:
    {
        'sum': <time in seconds, float>,
        'children': {
            '<child_name>': {
                ...child values
            }
        }
    }
    

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

sipro-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

sipro-1.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file sipro-1.0.0.tar.gz.

File metadata

  • Download URL: sipro-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for sipro-1.0.0.tar.gz
Algorithm Hash digest
SHA256 52bac15df82c99e8a053ca4d55376af0a7ead6c9b5e446334a58ca6d44bcba91
MD5 9ebd95b2ee9613b497e82c6b1cf6dbff
BLAKE2b-256 cda2ff73ecf1a448b16fa9ddaa1afc12414c326679fbf6294330005900a9874f

See more details on using hashes here.

File details

Details for the file sipro-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sipro-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for sipro-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b18c9254f3db135ea0d66d43ff14666b66a163cc8d543d342c5eb90787bca2f
MD5 ed2f8e877cc5a87f9e42c17c7328721a
BLAKE2b-256 36e6e03891f3bb20b1c33d7f4ff38d3474cb4c21ccb851b3f6e86da3c267046f

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