Migrate all benchmark to criterion
This commit is contained in:
parent
0acc8bdd12
commit
fa07a5e377
28
Cargo.toml
28
Cargo.toml
|
@ -72,10 +72,38 @@ auto-initialize = []
|
|||
# Optimizes PyObject to Vec conversion and so on.
|
||||
nightly = []
|
||||
|
||||
[[bench]]
|
||||
name = "bench_call"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_dict"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_gil"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_list"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_pyclass"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_pyobject"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_set"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "bench_tuple"
|
||||
harness = false
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"pyo3-macros",
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use test::Bencher;
|
||||
|
||||
macro_rules! test_module {
|
||||
($py:ident, $code:literal) => {
|
||||
|
@ -11,7 +9,6 @@ macro_rules! test_module {
|
|||
};
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_call_0(b: &mut Bencher) {
|
||||
Python::with_gil(|py| {
|
||||
let module = test_module!(
|
||||
|
@ -31,7 +28,6 @@ fn bench_call_0(b: &mut Bencher) {
|
|||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_call_method_0(b: &mut Bencher) {
|
||||
Python::with_gil(|py| {
|
||||
let module = test_module!(
|
||||
|
@ -51,3 +47,11 @@ fn bench_call_method_0(b: &mut Bencher) {
|
|||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("call_0", bench_call_0);
|
||||
c.bench_function("call_method_0", bench_call_method_0);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::IntoPyDict;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn iter_dict(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -21,7 +18,6 @@ fn iter_dict(b: &mut Bencher) {
|
|||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn dict_get_item(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -35,7 +31,6 @@ fn dict_get_item(b: &mut Bencher) {
|
|||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn extract_hashmap(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -44,7 +39,6 @@ fn extract_hashmap(b: &mut Bencher) {
|
|||
b.iter(|| HashMap::<u64, u64>::extract(dict));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn extract_btreemap(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -53,7 +47,6 @@ fn extract_btreemap(b: &mut Bencher) {
|
|||
b.iter(|| BTreeMap::<u64, u64>::extract(dict));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg(feature = "hashbrown")]
|
||||
fn extract_hashbrown_map(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -62,3 +55,16 @@ fn extract_hashbrown_map(b: &mut Bencher) {
|
|||
let dict = (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict(py);
|
||||
b.iter(|| hashbrown::HashMap::<u64, u64>::extract(dict));
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("iter_dict", iter_dict);
|
||||
c.bench_function("dict_get_item", dict_get_item);
|
||||
c.bench_function("extract_hashmap", extract_hashmap);
|
||||
c.bench_function("extract_btreemap", extract_btreemap);
|
||||
|
||||
#[cfg(feature = "hashbrown")]
|
||||
c.bench_function("extract_hashbrown_map", extract_hashbrown_map);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyList;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn iter_list(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -20,7 +17,6 @@ fn iter_list(b: &mut Bencher) {
|
|||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn list_get_item(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -33,3 +29,11 @@ fn list_get_item(b: &mut Bencher) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("iter_list", iter_list);
|
||||
c.bench_function("list_get_item", list_get_item);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::{class::PyObjectProtocol, prelude::*, type_object::LazyStaticType};
|
||||
use test::Bencher;
|
||||
|
||||
/// This is a feature-rich class instance used to benchmark various parts of the pyclass lifecycle.
|
||||
#[pyclass]
|
||||
|
@ -33,7 +31,6 @@ impl PyObjectProtocol for MyClass {
|
|||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn first_time_init(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -44,3 +41,10 @@ fn first_time_init(b: &mut Bencher) {
|
|||
ty.get_or_init::<MyClass>(py);
|
||||
});
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("first_time_init", first_time_init);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn drop_many_objects(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -14,3 +11,10 @@ fn drop_many_objects(b: &mut Bencher) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("drop_many_objects", drop_many_objects);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PySet;
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn iter_set(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -21,7 +18,6 @@ fn iter_set(b: &mut Bencher) {
|
|||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn extract_hashset(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -30,7 +26,6 @@ fn extract_hashset(b: &mut Bencher) {
|
|||
b.iter(|| HashSet::<u64>::extract(set));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn extract_btreeset(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -39,7 +34,6 @@ fn extract_btreeset(b: &mut Bencher) {
|
|||
b.iter(|| BTreeSet::<u64>::extract(set));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg(feature = "hashbrown")]
|
||||
fn extract_hashbrown_set(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -48,3 +42,15 @@ fn extract_hashbrown_set(b: &mut Bencher) {
|
|||
let set = PySet::new(py, &(0..LEN).collect::<Vec<_>>()).unwrap();
|
||||
b.iter(|| hashbrown::HashSet::<u64>::extract(set));
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("iter_set", iter_set);
|
||||
c.bench_function("extract_hashset", extract_hashset);
|
||||
c.bench_function("extract_btreeset", extract_btreeset);
|
||||
|
||||
#[cfg(feature = "hashbrown")]
|
||||
c.bench_function("extract_hashbrown_set", extract_hashbrown_set);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#![feature(test)]
|
||||
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
||||
|
||||
extern crate test;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyTuple;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn iter_tuple(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -20,7 +17,6 @@ fn iter_tuple(b: &mut Bencher) {
|
|||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn tuple_get_item(b: &mut Bencher) {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -33,3 +29,11 @@ fn tuple_get_item(b: &mut Bencher) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("iter_tuple", iter_tuple);
|
||||
c.bench_function("tuple_get_item", tuple_get_item);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in a new issue