Skip to main content

Estimate Asymptotic Runtime Complexity from Bytecode executions

Project description

Python Performance Analysis Library or py-pal is a bytecode profiling toolkit. See the Documentation.

Installation

This project requires CPython and a C compiler to run. Install Python >= 3.7, then install py-pal by running:

pip install py-pal

Development

To set up a development environment:

  1. Install Python >= 3.7 and a C compiler.

  2. Create a virtualenv

    python3 -m venv venv

  3. Install the development dependencies

    pip install -r dev-requirements.txt

Build the py-pal package

python3 setup.py develop

This compiles the C extensions using Cython, packages everything together and places it into the virtualenv. Note that changes on the cython files (.pyx extension) require recompilation i.e. rerunning the above command.

Run all the tests

pytest tests tests_cython

Usage

Calling py-pal as module with

python -m py_pal file.py

or

pypal file.py

Measure specific functions using the decorator:

from py_pal.core import profile

@profile
def test():
    pass

Using the context manager:

from py_pal.estimator import AllArgumentEstimator
from py_pal.tracer import Tracer

with Tracer() as t:
    pass

estimator = AllArgumentEstimator(t)
res = estimator.export()

# Do something with the resulting DataFrame
print(res)

Using the API:

from py_pal.estimator import AllArgumentEstimator
from py_pal.tracer import Tracer


t = Tracer()
t.trace()

# Your function
pass

t.stop()
estimator = AllArgumentEstimator(t)
res = estimator.export()

# Do something with the resulting DataFrame
print(res)

Modes

Profiling and Performance Testing

Restrictions

The Tracing process does not work for multi-threaded code.

Tracing processes

FAQ

Why not use a standard profiler?

Using absolute timing data vs synthetic timing data using opcodes.

Licensing Notes

This work integrates some code from the big_O project. More specifically, most code in py_pal.complexity, py_pal.datagen and py_pal.estimator.Estimator.infer_complexity is adapted from bigO. What’s New in Py-PAL 1.0.0 ==========================

  • More thorough testing from different combinations of requirements and Python versions.

  • Bug fixes

What’s New in Py-PAL 0.2.1

Refactoring

The estimator module was refactored which introduces a slight change to the API. Classes inheriting from Estimator now only specify how to transform the collected data with respect to the arguments of the function.

Instead of ComplexityEstimator you should use the AllArgumentEstimator class. Additionally there is the SeparateArgumentEstimator which is experimental.

What’s New in Py-PAL 0.1.6

More accurate Data Collection

The Tracer is enhanced by measuring builtin function calls with AdvancedOpcodeMetric.

Opcodes resembling a function call .e.g FUNCTION_CALL are filtered for built in function calls. If the called function is found in the complexity mapping a synthetic Opcode weight gets assigned. A builtin function call is evaluated using its argument and a pre-defined runtime complexity e.g. O(n log n) for sort().

  • The feature is enabled by default

  • The calculation produces a performance overhead and can be disabled by providing a OpcodeMetric instance to the Tracer

  • The AdvancedOpcodeMetric instance assigned to the Tracer provides statistics about how many builtin function calls were observed and how many were found in the complexity map

Bugfixes

  • Cleaning data after normalization introduced wrong data points

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

py-pal-1.0.0.tar.gz (172.1 kB view hashes)

Uploaded Source

Built Distributions

py_pal-1.0.0-cp39-cp39-manylinux2010_x86_64.whl (737.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

py_pal-1.0.0-cp39-cp39-manylinux1_x86_64.whl (737.7 kB view hashes)

Uploaded CPython 3.9

py_pal-1.0.0-cp38-cp38-manylinux2010_x86_64.whl (766.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

py_pal-1.0.0-cp38-cp38-manylinux1_x86_64.whl (766.2 kB view hashes)

Uploaded CPython 3.8

py_pal-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl (676.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

py_pal-1.0.0-cp37-cp37m-manylinux1_x86_64.whl (676.2 kB view hashes)

Uploaded CPython 3.7m

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