Skip to main content

A convenient wrapper library for different Python profilers.

Project description

PyProfilers

PyProfilers is collection of wrapper functions for various Python profilers which aims to make profiling more convenient.

Installing

Install and update using pip:

pip install -U pyprofilers

Simple examples

Import PyProfilers

import pyprofilers as pp

Profile with cProfile

Use the standard Python cProfile to list the cumulative time spent in the function func and all its subfunctions:

@pp.profile(sort_by='cumulative', out_lines=30)
def func():
  ...
  • sort_by can be used to sort the results according to the supplied criteria. All criterias can be found here.
  • out_lines controls the number of lines in results. Use None or ommit the arugment to show all.

Profile with line_profiler

Use the line_profiler to list time spent within each line of func:

@pp.profile_by_line(exit=1)
def func():
  ...

Set exit to True to stop the execution after the first call to func returns. This is useful if func is called multiple times to avoid the repeated output of the profiler statistics.

Simple Timer

To just time the execution of a function use the simple_timer decoration:

@pp.simple_timer(num=1)
def func():
  ...

The num argument can be used to specify how often the function should be executed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for PyProfilers, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size PyProfilers-0.1.3.tar.gz (15.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page