update set benchmarks

This commit is contained in:
David Hewitt 2024-01-17 10:49:21 +00:00
parent 06c95432c6
commit 4e24e680e8
1 changed files with 9 additions and 13 deletions

View File

@ -10,21 +10,17 @@ fn set_new(b: &mut Bencher<'_>) {
// Create Python objects up-front, so that the benchmark doesn't need to include
// the cost of allocating LEN Python integers
let elements: Vec<PyObject> = (0..LEN).map(|i| i.into_py(py)).collect();
b.iter(|| {
let pool = unsafe { py.new_pool() };
PySet::new(py, &elements).unwrap();
drop(pool);
});
b.iter_with_large_drop(|| PySet::new_bound(py, &elements).unwrap());
});
}
fn iter_set(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
const LEN: usize = 100_000;
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
let set = PySet::new_bound(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
let mut sum = 0;
b.iter(|| {
for x in set {
for x in set.iter() {
let i: u64 = x.extract().unwrap();
sum += i;
}
@ -35,16 +31,16 @@ fn iter_set(b: &mut Bencher<'_>) {
fn extract_hashset(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
const LEN: usize = 100_000;
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter(|| HashSet::<u64>::extract(set));
let set = PySet::new_bound(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter_with_large_drop(|| HashSet::<u64>::extract(set.as_gil_ref()));
});
}
fn extract_btreeset(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
const LEN: usize = 100_000;
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter(|| BTreeSet::<u64>::extract(set));
let set = PySet::new_bound(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter_with_large_drop(|| BTreeSet::<u64>::extract(set.as_gil_ref()));
});
}
@ -52,8 +48,8 @@ fn extract_btreeset(b: &mut Bencher<'_>) {
fn extract_hashbrown_set(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
const LEN: usize = 100_000;
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter(|| hashbrown::HashSet::<u64>::extract(set));
let set = PySet::new_bound(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
b.iter_with_large_drop(|| hashbrown::HashSet::<u64>::extract(set.as_gil_ref()));
});
}