From 57a49a2b12c7b8b0f610cf5977eefcdf7bc78f8b Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 23 Jan 2024 08:44:47 +0000 Subject: [PATCH] update tuple benchmarks for bound API --- pyo3-benches/benches/bench_list.rs | 2 +- pyo3-benches/benches/bench_tuple.rs | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pyo3-benches/benches/bench_list.rs b/pyo3-benches/benches/bench_list.rs index 6f8a678b..f4f746f6 100644 --- a/pyo3-benches/benches/bench_list.rs +++ b/pyo3-benches/benches/bench_list.rs @@ -20,7 +20,7 @@ fn iter_list(b: &mut Bencher<'_>) { fn list_new(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - b.iter(|| PyList::new_bound(py, 0..LEN)); + b.iter_with_large_drop(|| PyList::new_bound(py, 0..LEN)); }); } diff --git a/pyo3-benches/benches/bench_tuple.rs b/pyo3-benches/benches/bench_tuple.rs index f224ee1b..57920c25 100644 --- a/pyo3-benches/benches/bench_tuple.rs +++ b/pyo3-benches/benches/bench_tuple.rs @@ -6,10 +6,10 @@ use pyo3::types::{PyList, PySequence, PyTuple}; fn iter_tuple(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 100_000; - let tuple = PyTuple::new(py, 0..LEN); + let tuple = PyTuple::new_bound(py, 0..LEN); let mut sum = 0; b.iter(|| { - for x in tuple { + for x in tuple.iter_borrowed() { let i: u64 = x.extract().unwrap(); sum += i; } @@ -20,14 +20,14 @@ fn iter_tuple(b: &mut Bencher<'_>) { fn tuple_new(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - b.iter(|| PyTuple::new(py, 0..LEN)); + b.iter_with_large_drop(|| PyTuple::new_bound(py, 0..LEN)); }); } fn tuple_get_item(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let tuple = PyTuple::new(py, 0..LEN); + let tuple = PyTuple::new_bound(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -41,7 +41,7 @@ fn tuple_get_item(b: &mut Bencher<'_>) { fn tuple_get_item_unchecked(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let tuple = PyTuple::new(py, 0..LEN); + let tuple = PyTuple::new_bound(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -56,7 +56,7 @@ fn tuple_get_item_unchecked(b: &mut Bencher<'_>) { fn sequence_from_tuple(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let tuple = PyTuple::new(py, 0..LEN).to_object(py); + let tuple = PyTuple::new_bound(py, 0..LEN).to_object(py); b.iter(|| tuple.extract::<&PySequence>(py).unwrap()); }); } @@ -64,22 +64,16 @@ fn sequence_from_tuple(b: &mut Bencher<'_>) { fn tuple_new_list(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let tuple = PyTuple::new(py, 0..LEN); - b.iter(|| { - let _pool = unsafe { py.new_pool() }; - let _ = PyList::new(py, tuple); - }); + let tuple = PyTuple::new_bound(py, 0..LEN); + b.iter_with_large_drop(|| PyList::new_bound(py, tuple.iter_borrowed())); }); } fn tuple_to_list(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let tuple = PyTuple::new(py, 0..LEN); - b.iter(|| { - let _pool = unsafe { py.new_pool() }; - let _ = tuple.to_list(); - }); + let tuple = PyTuple::new_bound(py, 0..LEN); + b.iter_with_large_drop(|| tuple.to_list()); }); }