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(
# ...
)
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:
- Making a flat list out of list of lists in Python
- Most efficient way to map function over numpy array
- numpy: most efficient frequency counts for unique values in an array
- Most efficient way to reverse a numpy array
- How to add an extra column to an numpy array
- Initializing numpy matrix to something other than zero or one
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.
Metadata
Release files for perfplot 0.10.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| perfplot-0.10.2.tar.gz | 25.0 kB | Without provenance | Details for perfplot-0.10.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| perfplot-0.10.2-py3-none-any.whl | Python 3 | none | any | Details for perfplot-0.10.2-py3-none-any.whl |
Total release size: 46.2 kB
Release files / perfplot-0.10.2.tar.gz
| Download URL | perfplot-0.10.2.tar.gz |
|---|---|
| Size | 25.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d76daa72334564b5c8825663f24d15db55ea33e938b34595a146e5e44ed87e41
|
|
BLAKE2b-256 checksum How to use checksums |
974151d8b9caa150a050de16a229f627e4b37515dbff0075259e4e75aff7218b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.1
|
Release files / perfplot-0.10.2-py3-none-any.whl
| Download URL | perfplot-0.10.2-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
545ce0f7f22509ad00092d79a794cdc6e9805383e6cedab2bfed3519a7ef4e19
|
|
BLAKE2b-256 checksum How to use checksums |
2085ffaf2c1f92d17916c089a5c860d23b3117398f19f467fd1de1026d03aebc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.1
|
Security for perfplot 0.10.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.