benches: add bench_err

This commit is contained in:
David Hewitt 2021-07-13 21:22:19 +01:00
parent 243e5eea13
commit dc58815143
2 changed files with 28 additions and 0 deletions

View File

@ -77,6 +77,10 @@ nightly = []
name = "bench_call" name = "bench_call"
harness = false harness = false
[[bench]]
name = "bench_err"
harness = false
[[bench]] [[bench]]
name = "bench_dict" name = "bench_dict"
harness = false harness = false

24
benches/bench_err.rs Normal file
View File

@ -0,0 +1,24 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use pyo3::{exceptions::PyValueError, prelude::*};
fn err_new_restore_and_fetch(b: &mut Bencher) {
Python::with_gil(|py| {
b.iter(|| {
PyValueError::new_err("some exception message").restore(py);
PyErr::fetch(py)
})
})
}
fn err_new_without_gil(b: &mut Bencher) {
b.iter(|| PyValueError::new_err("some exception message"))
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("err_new_restore_and_fetch", err_new_restore_and_fetch);
c.bench_function("err_new_without_gil", err_new_without_gil);
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);