Skip to main content

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

Release files for penchmark 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for penchmark 0.1.0
File Size Uploaded
penchmark-0.1.0.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for penchmark 0.1.0
File Interpreter ABI Platform
penchmark-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / penchmark-0.1.0.tar.gz

Download URL penchmark-0.1.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fb9e3434fc2b4026f802fcbc11533b90ed3eb85ce4d6204bfd49ee5427086442
BLAKE2b-256 checksum
How to use checksums
40017e9287c4cd0d5d9c1607a39e002073031eace314fd820f22967060a5c4e7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / penchmark-0.1.0-py3-none-any.whl

Download URL penchmark-0.1.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7760af02d85b4b8e988cf5c91e79a4b1e2344631f0371a4db6477a3006c9e70c
BLAKE2b-256 checksum
How to use checksums
910d5118e1e88d41d6ff4bb1e7cf8ab15125fd13efe1ecf323451e5df9af1ce2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page