Skip to main content

A simple benchmarking package including visualization facilities.

The goal of this package is to provide a simple way to compare the performance of different approaches for different inputs and to visualize the result.

Documentation

Documentation Status

Downloads

PyPI Project GitHub Project

Installation

Using pip:

python -m pip install simple_benchmark

Or installing the most recent version directly from git:

python -m pip install git+https://github.com/MSeifert04/simple_benchmark.git

To utilize the all features of the library (for example visualization) you need to install the optional dependencies:

Or install them automatically using:

python -m pip install simple_benchmark[optional]

Getting started

Suppose you want to compare how NumPys sum and Pythons sum perform on lists of different sizes:

>>> from simple_benchmark import benchmark
>>> import numpy as np
>>> funcs = [sum, np.sum]
>>> arguments = {i: [1]*i for i in [1, 10, 100, 1000, 10000, 100000]}
>>> argument_name = 'list size'
>>> aliases = {sum: 'Python sum', np.sum: 'NumPy sum'}
>>> b = benchmark(funcs, arguments, argument_name, function_aliases=aliases)

The result can be visualized with pandas (needs to be installed):

>>> b
          Python sum  NumPy sum
1       9.640884e-08   0.000004
10      1.726930e-07   0.000004
100     7.935484e-07   0.000008
1000    7.040000e-06   0.000042
10000   6.910000e-05   0.000378
100000  6.899000e-04   0.003941

Or with matplotlib (has to be installed too):

>>> b.plot()

To save the plotted benchmark as PNG file:

>>> import matplotlib.pyplot as plt
>>> plt.savefig('sum_example.png')
./docs/source/sum_example.png

Command-Line interface

It’s an experiment to run it as command-line tool, especially useful if you want to run it on multiple files and don’t want the boilerplate.

File sum.py:

import numpy as np

def bench_sum(l, func=sum):  # <-- function name needs to start with "bench_"
   return func(l)

def bench_numpy_sum(l, func=np.sum):  # <-- using func parameter with the actual function helps
   return np.sum(l)

def args_list_length():  # <-- function providing the argument starts with "args_"
   for i in [1, 10, 100, 1000, 10000, 100000]:
      yield i, [1] * i

Then run:

$ python -m simple_benchmark sum.py sum.png

With a similar result:

./docs/source/sum_example_cli.png

Metadata

Release files for simple-benchmark 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 simple-benchmark 0.1.0
File Size Uploaded
simple_benchmark-0.1.0.tar.gz 13.1 kB Details

Release files / simple_benchmark-0.1.0.tar.gz

Download URL simple_benchmark-0.1.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2be6a87ef024c1387ec54de8792e80192080cb0572ebd049fdb1b60388d4251e
BLAKE2b-256 checksum
How to use checksums
b0b1f0183b9abcc3f507e51303558a56e4750823ebb1ca857403fbea6e6b2f99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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