Code Monkey home page Code Monkey logo

penchmark's Introduction

Python benchmark library

MIT License PyPI version Python package codecov

Installation

pip install penchmark
pip install penchmark[charts]

Example

Classes Callee, InData

from penchmark import benchmark_and_print, Callee, InData

callees = (
    Callee(callee_name='mul', callee=lambda x: x[0] * x[1]),
    Callee(callee_name='nop', callee=lambda x: x)
)
dataset = (
    InData(name='small-data', data=(2, 1), count_of_call=100000),
    InData(name='big-data', data=(200, 10), count_of_call=1000),
    InData(name='skipped-data', data=(1, 1), count_of_call=0)
)
benchmark_and_print(callees, dataset)

Tuples

from penchmark import benchmark_and_print

callees = (
    ('mul', lambda x: x[0] * x[1]),
    ('nop', lambda x: x)
)
dataset = (
    ('small-data', (2, 1), 100000),
    ('big-data', (200, 10), 1000),
    ('skipped-data', (1, 1), 0)
)
benchmark_and_print(callees, dataset)

Auto generate names of callees

from penchmark import benchmark_and_print

def mul(x): return x[0] * x[1]
def nop(x): return x

dataset = (
    ('small-data', (2, 1), 100000),
    ('big-data', (200, 10), 1000),
    ('skipped-data', (1, 1), 0)
)
benchmark_and_print((mul, nop), dataset)

Markdown result

small-data
callee_name elapsed ratio
nop 0.0050 1.0000
mul 0.0080 1.5842
big-data
callee_name elapsed ratio
nop 0.0000 1.0000
mul 0.0001 1.7201
Summary
callee_name mean median
nop 1.0000 1.0000
mul 1.6521 1.6521

Console mode result

...
benchmark_and_print((mul, nop), dataset, markdown=False)
SMALL-DATA

callee_name      elapsed    ratio
-------------  ---------  -------
nop               0.0050   1.0000
mul               0.0079   1.5944

BIG-DATA

callee_name      elapsed    ratio
-------------  ---------  -------
nop               0.0001   1.0000
mul               0.0001   1.7565

SUMMARY

callee_name      mean    median
-------------  ------  --------
nop            1.0000    1.0000
mul            1.6754    1.6754

Callee with exceptions

from penchmark import benchmark_and_print

def callee_with_exceptions(x):
    if not x:
        raise Exception()

callees = (
    ('callee-with-exceptions', callee_with_exceptions),
    ('callee-without-exceptions', lambda x: None)
)
dataset = (
    ('valid-data', True, 10),
    ('invalid-data', False, 10),
)
benchmark_and_print(callees, dataset)
valid-data
callee_name elapsed ratio
callee-without-exceptions 0.00000 1
callee-with-exceptions 0.00000 2.36735
invalid-data
callee_name elapsed ratio
callee-without-exceptions 0.00000 1
callee-with-exceptions ERROR
Summary
callee_name mean median
callee-without-exceptions 1 1

Expected using InData

from penchmark import benchmark_and_print, InData

def mul2_1(sequ): return [x * 2 for x in sequ]
def mul2_2(sequ): return [x + x for x in sequ]

dataset = (
    InData(name='small-data', data=(2, 1), count_of_call=100000, expected=[4, 2]),
    InData(name='big-data', data=(200, 10), count_of_call=1000, expected=[400, 20]),
    InData(name='skipped-data', data=(1, 1), count_of_call=0, expected=[2, 2])
)
benchmark_and_print((mul2_1, mul2_2), dataset)

Expected using tuples

from penchmark import benchmark_and_print

def mul2_1(sequ): return [x * 2 for x in sequ]
def mul2_2(sequ): return [x + x for x in sequ]

dataset = (
    ('small-data', (2, 1), 100000, [4, 2]),
    ('big-data', (200, 10), 1000, [400, 20]),
    ('skipped-data', (1, 1), 0, [2, 2])
)
benchmark_and_print((mul2_1, mul2_2), dataset)

small-data

callee_name elapsed ratio
mul2_2 0.02114 1
mul2_1 0.02317 1.09603

big-data

callee_name elapsed ratio
mul2_2 0.00021 1
mul2_1 0.00022 1.01147

Summary

callee_name mean median
mul2_2 1 1
mul2_1 1.05375 1.05375

penchmark's People

Contributors

ruzzz avatar

Watchers

 avatar  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.