update tuple benchmarks for bound API

This commit is contained in:
David Hewitt 2024-01-23 08:44:47 +00:00
parent 674f7282d8
commit 57a49a2b12
2 changed files with 11 additions and 17 deletions

View File

@ -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));
});
}

View File

@ -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());
});
}