Skip to content

Commit 7f5e79f

Browse files
committed
Add downcast to benchmarks, in addition to extract.
1 parent a8aac58 commit 7f5e79f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

benches/array.rs

+21
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ fn extract_failure(bencher: &mut Bencher) {
3030
});
3131
}
3232

33+
#[bench]
34+
fn downcast_success(bencher: &mut Bencher) {
35+
Python::with_gil(|py| {
36+
let any: &PyAny = PyArray2::<f64>::zeros(py, (10, 10), false);
37+
38+
bencher.iter(|| {
39+
black_box(any).downcast::<PyArray2<f64>>().unwrap();
40+
});
41+
});
42+
}
43+
44+
#[bench]
45+
fn downcast_failure(bencher: &mut Bencher) {
46+
Python::with_gil(|py| {
47+
let any: &PyAny = PyArray2::<i32>::zeros(py, (10, 10), false);
48+
49+
bencher.iter(|| {
50+
black_box(any).downcast::<PyArray2<f64>>().unwrap_err();
51+
});
52+
});
53+
}
3354
struct Iter(Range<usize>);
3455

3556
impl Iterator for Iter {

0 commit comments

Comments
 (0)