Python module to benchmark and compare functions
Project description
pybenchmarker
A simple utility for comparing the efficiency of functionally-equivalent functions in Python.
Installation
pip install pybenchmarker
BenchmarkN class
Problem
Input: two lists of equal length list_0
, list_1
.
Output: a list of booleans encoding which items of list_0
are in
list_1
.
What's the fastest way to do this?
import numpy as np
from pybenchmarker import BenchmarkN, sizes
from random import randint
@sizes([2**k for k in range(18)])
def argfunc(n):
return [randint(1, n) for i in range(n)], [randint(1, n) for i in range(n)]
def naive_lcomp(lists):
return [x in lists[1] for x in lists[0]]
def set_other(lists):
s = set(lists[1])
return [x in s for x in lists[0]]
def numpy_isin(lists):
return list(np.isin(lists[0], lists[1]))
if __name__ == '__main__':
title = "list_3: list[bool], encoding which items in list_1 are in list_2"
b = BenchmarkN(functions=[naive_lcomp, set_other, numpy_isin],
argfunc=argfunc)
b.plot(xlabel="n", title=title, fname="my_figure", transparent=True,
dpi=300)
This results in the following plot:
Inspiration
This project was inspired by perfplot, which was used to contribute to
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pybenchmarker-0.1.0-1.tar.gz
(9.3 kB
view details)
Built Distribution
File details
Details for the file pybenchmarker-0.1.0-1.tar.gz
.
File metadata
- Download URL: pybenchmarker-0.1.0-1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e0344963fbbe63b252e9462628960f05f1754210667cde1fb586e62ea738a0d |
|
MD5 | 902c29772ff0f9bd2b58167eef368178 |
|
BLAKE2b-256 | 4521e4160ab890b51dd4b3ccffa208f1824e000bab2cba9e16aa3a26e5808775 |
File details
Details for the file pybenchmarker-0.1.0-1-py3-none-any.whl
.
File metadata
- Download URL: pybenchmarker-0.1.0-1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 494d4e92d39994fc48aaa1a46bd4536670ca1665df2f71af5987106e16df5399 |
|
MD5 | 68e61d5a790ca898f0370f43367a8485 |
|
BLAKE2b-256 | 2ce7f405fe95a81d50882d7e66d8ed99e833c0a7887a80c8a582440b9cf8c25b |