pyo3/pyo3-benches/benches/bench_err.rs

25 lines
738 B
Rust
Raw Permalink Normal View History

2023-08-29 06:26:36 +00:00
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};
2021-07-13 20:22:19 +00:00
use pyo3::{exceptions::PyValueError, prelude::*};
2022-03-23 07:07:28 +00:00
fn err_new_restore_and_fetch(b: &mut Bencher<'_>) {
2021-07-13 20:22:19 +00:00
Python::with_gil(|py| {
b.iter(|| {
PyValueError::new_err("some exception message").restore(py);
PyErr::fetch(py)
})
})
}
2022-03-23 07:07:28 +00:00
fn err_new_without_gil(b: &mut Bencher<'_>) {
2021-07-13 20:22:19 +00:00
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);