2022-04-03 10:27:34 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
|
|
|
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
2022-12-24 19:17:25 +00:00
|
|
|
use pyo3::intern;
|
2022-04-03 10:27:34 +00:00
|
|
|
|
|
|
|
fn getattr_direct(b: &mut Bencher<'_>) {
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
let sys = py.import("sys").unwrap();
|
|
|
|
|
|
|
|
b.iter(|| sys.getattr("version").unwrap());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn getattr_intern(b: &mut Bencher<'_>) {
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
let sys = py.import("sys").unwrap();
|
|
|
|
|
|
|
|
b.iter(|| sys.getattr(intern!(py, "version")).unwrap());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
|
|
c.bench_function("getattr_direct", getattr_direct);
|
|
|
|
c.bench_function("getattr_intern", getattr_intern);
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
|
|
criterion_main!(benches);
|