GithubHelp home page GithubHelp logo

henrystoldt / perfplot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nschloe/perfplot

0.0 0.0 0.0 545 KB

Performance plots for Python code

License: GNU General Public License v3.0

Python 93.35% Makefile 6.65%

perfplot's Introduction

perfplot

gh-actions codecov Code style: black PyPI pyversions 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

perfplot.show(
    setup=lambda n: numpy.random.rand(n),  # or simply 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
    # colors=None,
    # 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.

Benchmarking and plotting can be separated, too. 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 or upgrade.

Testing

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

pytest

License

This software is published under the GPLv3 license.

perfplot's People

Contributors

asongtoruin avatar carsonip avatar dizcza avatar gchilczuk avatar hamogu avatar nicholaswon47 avatar nschloe avatar skilkis avatar stevehere avatar unutbu avatar wobedi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.