How to use perfplot - 10 common examples

To help you get started, we’ve selected a few perfplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / perfplot / perfplot / main.py View on Github external
t, total_time = _b(data, kernel, repeat, timer, is_ns_timer, resolution)
                time_per_repetition = total_time / repeat

                remaining_time -= total_time
                repeat = int(remaining_time // time_per_repetition)
                if repeat > 0:
                    t2, _ = _b(data, kernel, repeat, timer, is_ns_timer, resolution)
                    t = min(t, t2)

                timings[k, i] = t

    except KeyboardInterrupt:
        timings = timings[:, :i]
        n_range = n_range[:i]

    data = PerfplotData(n_range, timings, flop, labels, colors, xlabel, title)
    return data
github nschloe / accupy / test / test_sums.py View on Github external
def test_speed_comparison1(n_range=None):
    if n_range is None:
        n_range = [2 ** k for k in range(2)]

    numpy.random.seed(0)
    perfplot.plot(
        setup=lambda n: numpy.random.rand(n, 100),
        kernels=[
            sum,
            lambda p: numpy.sum(p, axis=0),
            accupy.kahan_sum,
            lambda p: accupy.ksum(p, K=2),
            lambda p: accupy.ksum(p, K=3),
            accupy.fsum,
        ],
        labels=[
            "sum",
            "numpy.sum",
            "accupy.kahan_sum",
            "accupy.ksum[2]",
            "accupy.ksum[3]",
            "accupy.fsum",
github nschloe / accupy / test / test_dot.py View on Github external
def test_speed_comparison1(n_range=None):
    if n_range is None:
        n_range = [2 ** k for k in range(2)]

    numpy.random.seed(0)
    perfplot.plot(
        setup=lambda n: (numpy.random.rand(n, 100), numpy.random.rand(100, n)),
        kernels=[
            lambda xy: numpy.dot(*xy),
            lambda xy: accupy.kdot(*xy, K=2),
            lambda xy: accupy.kdot(*xy, K=3),
            lambda xy: accupy.fdot(*xy),
        ],
        labels=["numpy.dot", "accupy.kdot[2]", "accupy.kdot[3]", "accupy.fdot"],
        colors=plt.rcParams["axes.prop_cycle"].by_key()["color"][:4],
        n_range=n_range,
        title="dot(random(n, 100), random(100, n))",
        xlabel="n",
        logx=True,
        logy=True,
    )
    plt.gca().set_aspect(0.2)
github nschloe / colorio / test / test_comparisons.py View on Github external
Y_b = 20
    L_A = 64 / numpy.pi / 5

    c = 0.69  # average
    cam16 = colorio.CAM16(c, Y_b, L_A)

    def cio(x):
        return cam16.to_xyz100(x, "JCh")

    cam16_legacy = CAM16Legacy(c, Y_b, L_A)

    def cio_legacy(x):
        return cam16_legacy.to_xyz100(x, "JCh")

    perfplot.plot(
        setup=lambda n: numpy.random.rand(3, n),
        kernels=[cio, cio_legacy],
        n_range=100000 * numpy.arange(11),
        xlabel="Number of input samples",
    )

    # import matplotlib2tikz
    # matplotlib2tikz.save('fig.tikz')
    return
github nschloe / accupy / test / test_dot.py View on Github external
def test_speed_comparison2(n_range=None):
    if n_range is None:
        n_range = [2 ** k for k in range(2)]

    numpy.random.seed(0)
    perfplot.plot(
        setup=lambda n: (numpy.random.rand(100, n), numpy.random.rand(n, 100)),
        kernels=[
            lambda xy: numpy.dot(*xy),
            lambda xy: accupy.kdot(*xy, K=2),
            lambda xy: accupy.kdot(*xy, K=3),
            lambda xy: accupy.fdot(*xy),
        ],
        labels=["numpy.dot", "accupy.kdot[2]", "accupy.kdot[3]", "accupy.fdot"],
        colors=plt.rcParams["axes.prop_cycle"].by_key()["color"][:4],
        n_range=n_range,
        title="dot(random(100, n), random(n, 100))",
        xlabel="n",
        logx=True,
        logy=True,
    )
    plt.gca().set_aspect(0.2)
github nschloe / accupy / test / test_sums.py View on Github external
def test_speed_comparison2(n_range=None):
    if n_range is None:
        n_range = [2 ** k for k in range(2)]

    numpy.random.seed(0)
    perfplot.plot(
        setup=lambda n: numpy.random.rand(100, n),
        kernels=[
            sum,
            lambda p: numpy.sum(p, axis=0),
            accupy.kahan_sum,
            lambda p: accupy.ksum(p, K=2),
            lambda p: accupy.ksum(p, K=3),
            accupy.fsum,
        ],
        labels=[
            "sum",
            "numpy.sum",
            "accupy.kahan_sum",
            "accupy.ksum[2]",
            "accupy.ksum[3]",
            "accupy.fsum",
github nschloe / dmsh / test / test_speed.py View on Github external
def test_speed(n=3):
    path_pts = [[0, 0], [0, 1], [1, 1], [1, 0]]
    path0 = path.Path(path_pts)
    path1 = pypathlib.ClosedPath(path_pts)

    def _mpl_path(pts):
        return path0.contains_points(pts)

    def _pypathlib_contains_points(pts):
        return path1.contains_points(pts)

    numpy.random.seed(0)

    perfplot.show(
        setup=lambda n: numpy.random.rand(n, 2),
        kernels=[_mpl_path, _pypathlib_contains_points],
        n_range=[2 ** k for k in range(n)],
        labels=["matplotlib.path.contains_points", "pypathlib.contains_points"],
        logx=True,
        logy=True,
        xlabel="num points",
    )
github nschloe / colorio / test / test_osa.py View on Github external
def test_speed(N=2):
    numpy.random.seed(1)
    osa = colorio.OsaUcs()
    cielab = colorio.CIELAB()
    # cam16 = colorio.CAM16(0.69, 20, L_A=64 / numpy.pi / 5)
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A=64 / numpy.pi / 5)

    # This close probably means that another figure hasn't been properly closed.
    import matplotlib.pyplot as plt
    plt.close()

    perfplot.show(
        # Don't use numpy.random.rand(3, n) to avoid the CIECAM breakdown
        setup=lambda n: numpy.outer(numpy.random.rand(3), numpy.ones(n)) * 10,
        equality_check=None,
        kernels=[
            osa.to_xyz100,
            cielab.to_xyz100,
            # cam16.to_xyz100,
            lambda Jsh: ciecam02.to_xyz100(Jsh, "Jsh"),
            numpy.cbrt,
        ],
        labels=["OSA-UCS", "CIELAB", "CIECAM02", "cbrt"],
        n_range=[2 ** n for n in range(N)],
        logx=True,
        logy=True,
        # relative_to=3
github nschloe / colorio / test / test_comparisons.py View on Github external
def setup(n):
        out = numpy.empty((3, n))
        rgb = numpy.random.rand(3)
        for k in range(3):
            out[k] = rgb[k]
        return out

    Y_b = 20
    L_A = 64 / numpy.pi / 5
    c = 0.69  # average
    cam16 = colorio.CAM16(c, Y_b, L_A)

    cam16_legacy = CAM16Legacy(c, Y_b, L_A)

    perfplot.show(
        setup=setup,
        kernels=[cam16.from_xyz100, cam16_legacy.from_xyz100],
        labels=["new", "legacy"],
        n_range=1000 * numpy.arange(6),
        equality_check=False,
    )
    return
github nschloe / perfplot / example / concat.py View on Github external
import numpy

import perfplot

perfplot.show(
    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)",
)

perfplot

Performance plots for Python code snippets

GPL-3.0
Latest version published 3 years ago

Package Health Score

49 / 100
Full package analysis