Skip to content
Performance plots for Python code
Branch: master
Clone or download
nschloe Merge pull request #46 from SteveHere/patch-1
Changed `dtype` for `timings` (line 113) to `numpy.uint64`
Latest commit c2546fb Jul 15, 2019


CircleCI codecov Code style: black PyPi Version GitHub stars PyPi downloads

perfplot extends Python's timeit by testing snippets with input parameters (e.g., the size of an array) and plotting the results. (By default, perfplot asserts the equality of the output of all snippets, too.)

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

import numpy
import perfplot
    setup=lambda n: numpy.random.rand(n),  # or simply setup=numpy.random.rand
        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)],
    # More optional arguments with their default values:
    # title=None,
    # logx=False,
    # logy=False,
    # equality_check=numpy.allclose,  # set to None to disable "correctness" assertion
    # automatic_order=True,
    # colors=None,
    # target_time_per_measurement=1.0,


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

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

out = perfplot.bench(
    # same arguments as above

Other examples:


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

pip3 install perfplot --user

to install or upgrade.


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



perfplot is published under the MIT license.

You can’t perform that action at this time.