Skip to main content

Performance plots for Python code snippets

Project description

perfplot

PyPi Version PyPI pyversions GitHub stars PyPi downloads

Discord

gh-actions codecov LGTM Code style: black

perfplot extends Python's timeit by testing snippets with input parameters (e.g., the size of an array) and plotting the results.

For example, to compare different NumPy array concatenation methods, the script

import numpy as np
import perfplot

perfplot.show(
    setup=lambda n: np.random.rand(n),  # or setup=np.random.rand
    kernels=[
        lambda a: np.c_[a, a],
        lambda a: np.stack([a, a]).T,
        lambda a: np.vstack([a, a]).T,
        lambda a: np.column_stack([a, a]),
        lambda a: np.concatenate([a[:, None], a[:, None]], axis=1),
    ],
    labels=["c_", "stack", "vstack", "column_stack", "concat"],
    n_range=[2 ** k for k in range(25)],
    xlabel="len(a)",
    # More optional arguments with their default values:
    # logx="auto",  # set to True or False to force scaling
    # logy="auto",
    # equality_check=np.allclose,  # set to None to disable "correctness" assertion
    # show_progress=True,
    # target_time_per_measurement=1.0,
    # max_time=None,  # maximum time per measurement
    # time_unit="s",  # set to one of ("auto", "s", "ms", "us", or "ns") to force plot units
    # relative_to=1,  # plot the timings relative to one of the measurements
    # flops=lambda n: 3*n,  # FLOPS plots
)

produces

Clearly, stack and vstack are the best options for large arrays.

(By default, perfplot asserts the equality of the output of all snippets, too.)

If your plot takes a while to generate, you can also use

perfplot.live(
    # ...
)
live

with the same arguments as above. It will plot the updates live.

Benchmarking and plotting can be separated. This allows multiple plots of the same data, for example:

out = perfplot.bench(
    # same arguments as above (except the plot-related ones, like time_unit or log*)
)
out.show()
out.save("perf.png", transparent=True, bbox_inches="tight")

Other examples:

Installation

perfplot is available from the Python Package Index, so simply do

pip install perfplot

to install.

Testing

To run the perfplot unit tests, check out this repository and type

tox

License

This software is published under the GPLv3 license.

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

perfplot-0.9.10.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

perfplot-0.9.10-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file perfplot-0.9.10.tar.gz.

File metadata

  • Download URL: perfplot-0.9.10.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for perfplot-0.9.10.tar.gz
Algorithm Hash digest
SHA256 b78ccf871f9c2188df014c2626f0f8c8d75121c6f184cef97a10baae552e4e00
MD5 f7a52935539495a84ee824d94f904aea
BLAKE2b-256 3a5f9d27b5d909a51924dabe7b855cba6418e7aa36c5d07cc342b81e1b6d5cc5

See more details on using hashes here.

File details

Details for the file perfplot-0.9.10-py3-none-any.whl.

File metadata

  • Download URL: perfplot-0.9.10-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for perfplot-0.9.10-py3-none-any.whl
Algorithm Hash digest
SHA256 63a958eb16070a31f55adb0a7d36a674605a47dcf407ea8f3512dd06523b7340
MD5 4649acd8620d07fe2b3aea3b4f35b165
BLAKE2b-256 4fc8959c4fd0066d974391d153a81287de9397b6e4b10de3b44a0e1e15a747ae

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