Skip to main content

Python code benchmark library

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

penchmark-0.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

penchmark-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file penchmark-0.1.0.tar.gz.

File metadata

  • Download URL: penchmark-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for penchmark-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb9e3434fc2b4026f802fcbc11533b90ed3eb85ce4d6204bfd49ee5427086442
MD5 d729f6fef72f3991ab448cd41ef8839a
BLAKE2b-256 40017e9287c4cd0d5d9c1607a39e002073031eace314fd820f22967060a5c4e7

See more details on using hashes here.

File details

Details for the file penchmark-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: penchmark-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for penchmark-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7760af02d85b4b8e988cf5c91e79a4b1e2344631f0371a4db6477a3006c9e70c
MD5 f8b9057a3c32dbfa0a311b324edcc861
BLAKE2b-256 910d5118e1e88d41d6ff4bb1e7cf8ab15125fd13efe1ecf323451e5df9af1ce2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page