2021-02-22 00:30:41 +00:00
|
|
|
import pyo3_benchmarks
|
|
|
|
|
|
|
|
|
|
|
|
def test_args_and_kwargs(benchmark):
|
|
|
|
benchmark(pyo3_benchmarks.args_and_kwargs, 1, 2, 3, a=4, foo=10)
|
|
|
|
|
|
|
|
|
|
|
|
def args_and_kwargs_py(*args, **kwargs):
|
|
|
|
return (args, kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def test_args_and_kwargs_py(benchmark):
|
|
|
|
rust = pyo3_benchmarks.args_and_kwargs(1, 2, 3, bar=4, foo=10)
|
|
|
|
py = args_and_kwargs_py(1, 2, 3, bar=4, foo=10)
|
|
|
|
assert rust == py
|
|
|
|
benchmark(args_and_kwargs_py, 1, 2, 3, bar=4, foo=10)
|
|
|
|
|
|
|
|
|
|
|
|
def test_mixed_args(benchmark):
|
|
|
|
benchmark(pyo3_benchmarks.mixed_args, 1, 2, 3, bar=4, foo=10)
|
|
|
|
|
|
|
|
|
|
|
|
def mixed_args_py(a, b=2, *args, c=4, **kwargs):
|
|
|
|
return (a, b, args, c, kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def test_mixed_args_py(benchmark):
|
|
|
|
rust = pyo3_benchmarks.mixed_args(1, 2, 3, bar=4, foo=10)
|
|
|
|
py = mixed_args_py(1, 2, 3, bar=4, foo=10)
|
|
|
|
assert rust == py
|
|
|
|
benchmark(mixed_args_py, 1, 2, 3, bar=4, foo=10)
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_args(benchmark):
|
|
|
|
benchmark(pyo3_benchmarks.no_args)
|
|
|
|
|
|
|
|
|
|
|
|
def no_args_py():
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_args_py(benchmark):
|
|
|
|
rust = pyo3_benchmarks.no_args()
|
|
|
|
py = no_args_py()
|
|
|
|
assert rust == py
|
|
|
|
benchmark(no_args_py)
|
2021-05-19 06:17:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_simple_args(benchmark):
|
|
|
|
benchmark(pyo3_benchmarks.simple_args, 1, 3, c=5)
|
|
|
|
|
|
|
|
|
|
|
|
def simple_args_py(a, b=2, *, c=4):
|
|
|
|
return a, b, c
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_args_py(benchmark):
|
|
|
|
rust = pyo3_benchmarks.simple_args(1, 3, c=5)
|
|
|
|
py = simple_args_py(1, 3, c=5)
|
|
|
|
assert rust == py
|
|
|
|
benchmark(simple_args_py, 1, 3, c=5)
|