Skip to main content

Performance plots for Python code snippets

Project description

perfplot

PyPi Version PyPI pyversions GitHub stars PyPi downloads

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
import perfplot

perfplot.show(
    setup=lambda n: numpy.random.rand(n),  # or setup=numpy.random.rand
    kernels=[
        lambda a: numpy.c_[a, a],
        lambda a: numpy.stack([a, a]).T,
        lambda a: numpy.vstack([a, a]).T,
        lambda a: numpy.column_stack([a, a]),
        lambda a: numpy.concatenate([a[:, None], a[:, None]], axis=1),
    ],
    labels=["c_", "stack", "vstack", "column_stack", "concat"],
    n_range=[2 ** k for k in range(15)],
    xlabel="len(a)",
    # logx=False,
    # logy=False,
    # More optional arguments with their default values:
    # title=None,
    # logx="auto",  # set to True or False to force scaling
    # logy="auto",
    # equality_check=numpy.allclose,  # set to None to disable "correctness" assertion
    # show_progress=True,
    # target_time_per_measurement=1.0,
    # 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.)

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

pytest

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.8.6.tar.gz (20.3 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.8.6-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: perfplot-0.8.6.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for perfplot-0.8.6.tar.gz
Algorithm Hash digest
SHA256 ba55fdc367ca24a02d858e41f68e299638454d1ed625a7d623f7cc4691c3b90b
MD5 f77f542c90a8776a50d23512fdbbe6d8
BLAKE2b-256 efb9f4bfbb8c00f5cb90e82d592413e99c9f8f3570ccb327e3724d9ecb4c7603

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perfplot-0.8.6-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for perfplot-0.8.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cf2baa7886ff4e1c8fde259936e3c4509423e50a85c9ba1e198838671c41d043
MD5 07ef95dbf5904741f7380066cdfc8ba4
BLAKE2b-256 5b0a782617dc59b2b914bf9732920528ee5c2ca63b335c769313acf5d11e92af

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