Giter Site home page Giter Site logo

hasenpfote / perfbench Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4.19 MB

perfbench measures execution time of code snippets with Timeit and uses Plotly to visualize the results.

License: MIT License

Python 96.85% Makefile 3.15%
python benchmark performance plot plotly visualization

perfbench's Introduction

License Build Status PyPI version Pyversions

perfbench

About

perfbench measures execution time of code snippets with Timeit and uses Plotly to visualize the results.

Feature

  • It is possible to select measurement modes.
  • It is possible to switch between layout sizes dynamically.
  • It is possible to switch between axes scales dynamically.
  • It is possible to switch between subplots dynamically.
  • The result of the benchmark can be saved locally as a html.
  • The result of the benchmark can be saved locally as a png. Requires installation of orca. When not to use the function, you do not need to install orca separately.

Compatibility

perfbench works with Python 3.5 or higher.

Dependencies

Installation

pip install perfbench

Usage

Plotting a single figure. Here is the demonstration.

import numpy as np
from perfbench import *


bm = Benchmark(
    datasets=[
        Dataset(
            factories=[
                lambda n: np.random.uniform(low=-1., high=1., size=n).astype(np.float64),
            ],
            title='float64'
        )
    ],
    dataset_sizes=[2 ** n for n in range(26)],
    kernels=[
        Kernel(
            stmt='np.around(DATASET)',
            setup='import numpy as np',
            label='around'
        ),
        Kernel(
            stmt='np.rint(DATASET)',
            setup='import numpy as np',
            label='rint'
        )
    ],
    xlabel='dataset sizes',
    title='around vs rint',
)
bm.run()
bm.plot()

plot1

Plotting multiple plots on a single figure. Here is the demonstration.

import numpy as np
from perfbench import *


bm = Benchmark(
    datasets=[
        Dataset(
            factories=[
                lambda n: np.random.uniform(low=-1., high=1., size=n).astype(np.float16),
            ],
            title='float16'
        ),
        Dataset(
            factories=[
                lambda n: np.random.uniform(low=-1., high=1., size=n).astype(np.float32),
            ],
            title='float32'
        ),
        Dataset(
            factories=[
                lambda n: np.random.uniform(low=-1., high=1., size=n).astype(np.float64),
            ],
            title='float64'
        )
    ],
    dataset_sizes=[2 ** n for n in range(26)],
    kernels=[
        Kernel(
            stmt='np.around(DATASET)',
            setup='import numpy as np',
            label='around'
        ),
        Kernel(
            stmt='np.rint(DATASET)',
            setup='import numpy as np',
            label='rint'
        ),
    ],
    xlabel='dataset sizes',
    title='around vs rint',
)
bm.run()
bm.plot()

plot2

plot2

Switching between layout sizes.

import numpy as np
from perfbench import *


bm = Benchmark(
    datasets=[
        Dataset(
            factories=[
                lambda n: np.random.uniform(low=-1., high=1., size=n).astype(np.float64),
            ],
            title='float64'
        )
    ],
    dataset_sizes=[2 ** n for n in range(26)],
    kernels=[
        Kernel(
            stmt='np.around(DATASET)',
            setup='import numpy as np',
            label='around'
        ),
        Kernel(
            stmt='np.rint(DATASET)',
            setup='import numpy as np',
            label='rint'
        )
    ],
    xlabel='dataset sizes',
    title='around vs rint',
    layout_sizes=[
        LayoutSize(width=640, height=480, label='VGA'),
        LayoutSize(width=800, height=600, label='SVGA'),
        LayoutSize(width=1024, height=768, label='XGA'),
        LayoutSize(width=1280, height=960, label='HD 720p'),
    ]
)
bm.run()
bm.plot()

plot3

Save as a html.

# same as above
bm.save_as_html(filepath='/path/to/file')

Save as a png.

# same as above
bm.save_as_png(filepath='/path/to/file', width=1280, height=960)

Other Here are a few examples.

License

This software is released under the MIT License, see LICENSE.

perfbench's People

Contributors

hasenpfote avatar

Watchers

 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.