Test for script result.
Project description
Benchmark utils
Utils for benchmark - wrapper over python timeit.
Tested on python 3.7 - 3.11
Install
Install from pypi:
pip install benchmark_utils
Or install from github repo:
pip install git+https://github.com/ayasyrev/benchmark_utils.git
Basic use.
Lets benchmark some (dump) functions.
from time import sleep
def func_to_test_1(sleep_time: float = 0.1, mult: int = 1) -> None:
"""simple 'sleep' func for test"""
sleep(sleep_time * mult)
def func_to_test_2(sleep_time: float = 0.11, mult: int = 1) -> None:
"""simple 'sleep' func for test"""
sleep(sleep_time * mult)
Let's create benchmark.
from benchmark_utils import Benchmark
bench = Benchmark(
[func_to_test_1, func_to_test_2],
)
bench
output
Benchmark(func_to_test_1, func_to_test_2)
Now we can benchmark that functions.
bench()
output
Func name | Sec / run
func_to_test_1: 0.10 0.0%
func_to_test_2: 0.11 -9.6%
We can run it again, all functions, some of it, exclude some and change number of repeats.
bench.run(num_repeats=10)
output
Func name | Sec / run
func_to_test_1: 0.10 0.0%
func_to_test_2: 0.11 -8.8%
After run, we can prunt results - sorted or not, reversed, compare results with best or not.
bench.print_results(reverse=True)
output
Func name | Sec / run
func_to_test_2: 0.11 0.0%
func_to_test_1: 0.10 9.7%
We can add functions to bencmark as list of funtions (or partial) ar as dictionary: {"name": function}
.
bench = Benchmark([
func_to_test_1,
partial(func_to_test_1, 0.12),
partial(func_to_test_1, sleep_time=0.11),
])
bench
output
Benchmark(func_to_test_1, func_to_test_1(0.12), func_to_test_1(sleep_time=0.11))
bench.run()
output
Func name | Sec / run
func_to_test_1: 0.10 0.0%
func_to_test_1(sleep_time=0.11): 0.11 -8.9%
func_to_test_1(0.12): 0.12 -16.5%
bench = Benchmark({
"func_1": func_to_test_1,
"func_2": func_to_test_2,
})
bench
output
Benchmark(func_1, func_2)
When we run benchmark script in terminal, we got pretty progress thanks to rich. Lets run example_1.py from example folder:
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
Built Distribution
Hashes for cli_result-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9680edf55c02127652c21d9800f6dd7384109c8cb52041b0bf5cfb3a7e10ebe |
|
MD5 | e3ecc9a2902643197883829729635cb2 |
|
BLAKE2b-256 | ab215a1ddc34e2cc4fcbf1756cfdd9f96fa0c3bc4df9c44ebc899638a6f2f41f |