@@ -10,7 +10,7 @@ use pyo3::{types::PyAnyMethods, Bound, IntoPyObjectExt, Python};
10
10
11
11
#[ bench]
12
12
fn extract_success ( bencher : & mut Bencher ) {
13
- Python :: with_gil ( |py| {
13
+ Python :: attach ( |py| {
14
14
let any = PyArray2 :: < f64 > :: zeros ( py, ( 10 , 10 ) , false ) . into_any ( ) ;
15
15
16
16
bencher. iter ( || {
@@ -23,7 +23,7 @@ fn extract_success(bencher: &mut Bencher) {
23
23
24
24
#[ bench]
25
25
fn extract_failure ( bencher : & mut Bencher ) {
26
- Python :: with_gil ( |py| {
26
+ Python :: attach ( |py| {
27
27
let any = PyArray2 :: < f64 > :: zeros ( py, ( 10 , 10 ) , false ) . into_any ( ) ;
28
28
29
29
bencher. iter ( || {
@@ -35,20 +35,20 @@ fn extract_failure(bencher: &mut Bencher) {
35
35
}
36
36
37
37
#[ bench]
38
- fn downcast_success ( bencher : & mut Bencher ) {
39
- Python :: with_gil ( |py| {
38
+ fn cast_success ( bencher : & mut Bencher ) {
39
+ Python :: attach ( |py| {
40
40
let any = PyArray2 :: < f64 > :: zeros ( py, ( 10 , 10 ) , false ) . into_any ( ) ;
41
41
42
- bencher. iter ( || black_box ( & any) . downcast :: < PyArray2 < f64 > > ( ) . unwrap ( ) ) ;
42
+ bencher. iter ( || black_box ( & any) . cast :: < PyArray2 < f64 > > ( ) . unwrap ( ) ) ;
43
43
} ) ;
44
44
}
45
45
46
46
#[ bench]
47
- fn downcast_failure ( bencher : & mut Bencher ) {
48
- Python :: with_gil ( |py| {
47
+ fn cast_failure ( bencher : & mut Bencher ) {
48
+ Python :: attach ( |py| {
49
49
let any = PyArray2 :: < f64 > :: zeros ( py, ( 10 , 10 ) , false ) . into_any ( ) ;
50
50
51
- bencher. iter ( || black_box ( & any) . downcast :: < PyArray2 < f64 > > ( ) . unwrap_err ( ) ) ;
51
+ bencher. iter ( || black_box ( & any) . cast :: < PyArray2 < f64 > > ( ) . unwrap_err ( ) ) ;
52
52
} ) ;
53
53
}
54
54
@@ -63,7 +63,7 @@ impl Iterator for Iter {
63
63
}
64
64
65
65
fn from_iter ( bencher : & mut Bencher , size : usize ) {
66
- Python :: with_gil ( |py| {
66
+ Python :: attach ( |py| {
67
67
bencher. iter ( || {
68
68
let iter = black_box ( Iter ( 0 ..size) ) ;
69
69
@@ -90,7 +90,7 @@ fn from_iter_large(bencher: &mut Bencher) {
90
90
fn from_slice ( bencher : & mut Bencher , size : usize ) {
91
91
let vec = ( 0 ..size) . collect :: < Vec < _ > > ( ) ;
92
92
93
- Python :: with_gil ( |py| {
93
+ Python :: attach ( |py| {
94
94
bencher. iter ( || {
95
95
let slice = black_box ( & vec) ;
96
96
@@ -115,13 +115,13 @@ fn from_slice_large(bencher: &mut Bencher) {
115
115
}
116
116
117
117
fn from_object_slice ( bencher : & mut Bencher , size : usize ) {
118
- let vec = Python :: with_gil ( |py| {
118
+ let vec = Python :: attach ( |py| {
119
119
( 0 ..size)
120
120
. map ( |val| val. into_py_any ( py) . unwrap ( ) )
121
121
. collect :: < Vec < _ > > ( )
122
122
} ) ;
123
123
124
- Python :: with_gil ( |py| {
124
+ Python :: attach ( |py| {
125
125
bencher. iter ( || {
126
126
let slice = black_box ( & vec) ;
127
127
@@ -148,7 +148,7 @@ fn from_object_slice_large(bencher: &mut Bencher) {
148
148
fn from_vec2 ( bencher : & mut Bencher , size : usize ) {
149
149
let vec2 = vec ! [ vec![ 0 ; size] ; size] ;
150
150
151
- Python :: with_gil ( |py| {
151
+ Python :: attach ( |py| {
152
152
bencher. iter ( || {
153
153
let vec2 = black_box ( & vec2) ;
154
154
@@ -175,7 +175,7 @@ fn from_vec2_large(bencher: &mut Bencher) {
175
175
fn from_vec3 ( bencher : & mut Bencher , size : usize ) {
176
176
let vec3 = vec ! [ vec![ vec![ 0 ; size] ; size] ; size] ;
177
177
178
- Python :: with_gil ( |py| {
178
+ Python :: attach ( |py| {
179
179
bencher. iter ( || {
180
180
let vec3 = black_box ( & vec3) ;
181
181
0 commit comments