Merge pull request #1617 from birkenfeld/simple_args_bench

pyo3_benchmarks: add a benchmark for the "only simple args" case
This commit is contained in:
Georg Brandl 2021-05-19 11:44:21 +02:00 committed by GitHub
commit 95d7fa27be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -24,10 +24,16 @@ fn mixed_args<'a>(
#[pyfunction]
fn no_args() {}
#[pyfunction(b = 2, "*", c = 4)]
fn simple_args(a: i32, b: i32, c: i32) -> (i32, i32, i32) {
(a, b, c)
}
#[pymodule]
fn _pyo3_benchmarks(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(args_and_kwargs, m)?)?;
m.add_function(wrap_pyfunction!(mixed_args, m)?)?;
m.add_function(wrap_pyfunction!(no_args, m)?)?;
m.add_function(wrap_pyfunction!(simple_args, m)?)?;
Ok(())
}

View File

@ -44,3 +44,18 @@ def test_no_args_py(benchmark):
py = no_args_py()
assert rust == py
benchmark(no_args_py)
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)