@@ -29,7 +29,7 @@ fn json<'a>(py: Python<'a>, code: &'a str) -> Bound<'a, PyAny> {
29
29
30
30
#[ bench]
31
31
fn ints_json ( bench : & mut Bencher ) {
32
- Python :: with_gil ( |py| {
32
+ Python :: attach ( |py| {
33
33
let validator = build_schema_validator ( py, c"{'type': 'int'}" ) ;
34
34
35
35
let result = validator
@@ -50,7 +50,7 @@ fn ints_json(bench: &mut Bencher) {
50
50
51
51
#[ bench]
52
52
fn ints_python ( bench : & mut Bencher ) {
53
- Python :: with_gil ( |py| {
53
+ Python :: attach ( |py| {
54
54
let validator = build_schema_validator ( py, c"{'type': 'int'}" ) ;
55
55
56
56
let Ok ( input) = 123_i64 . into_pyobject ( py) ;
@@ -73,7 +73,7 @@ fn ints_python(bench: &mut Bencher) {
73
73
74
74
#[ bench]
75
75
fn list_int_json ( bench : & mut Bencher ) {
76
- Python :: with_gil ( |py| {
76
+ Python :: attach ( |py| {
77
77
let validator = build_schema_validator ( py, c"{'type': 'list', 'items_schema': {'type': 'int'}}" ) ;
78
78
let code = format ! (
79
79
"[{}]" ,
@@ -104,7 +104,7 @@ fn list_int_input(py: Python<'_>) -> (SchemaValidator, PyObject) {
104
104
105
105
#[ bench]
106
106
fn list_int_python ( bench : & mut Bencher ) {
107
- Python :: with_gil ( |py| {
107
+ Python :: attach ( |py| {
108
108
let ( validator, input) = list_int_input ( py) ;
109
109
let input = black_box ( input. bind ( py) ) ;
110
110
bench. iter ( || {
@@ -118,7 +118,7 @@ fn list_int_python(bench: &mut Bencher) {
118
118
119
119
#[ bench]
120
120
fn list_int_python_isinstance ( bench : & mut Bencher ) {
121
- Python :: with_gil ( |py| {
121
+ Python :: attach ( |py| {
122
122
let ( validator, input) = list_int_input ( py) ;
123
123
let input = black_box ( input. bind ( py) ) ;
124
124
let v = validator
@@ -137,7 +137,7 @@ fn list_int_python_isinstance(bench: &mut Bencher) {
137
137
138
138
#[ bench]
139
139
fn list_error_json ( bench : & mut Bencher ) {
140
- Python :: with_gil ( |py| {
140
+ Python :: attach ( |py| {
141
141
let validator = build_schema_validator ( py, c"{'type': 'list', 'items_schema': {'type': 'int'}}" ) ;
142
142
let code = format ! (
143
143
"[{}]" ,
@@ -195,7 +195,7 @@ fn list_error_python_input(py: Python<'_>) -> (SchemaValidator, PyObject) {
195
195
196
196
#[ bench]
197
197
fn list_error_python ( bench : & mut Bencher ) {
198
- Python :: with_gil ( |py| {
198
+ Python :: attach ( |py| {
199
199
let ( validator, input) = list_error_python_input ( py) ;
200
200
201
201
let input = black_box ( input. bind ( py) ) ;
@@ -212,7 +212,7 @@ fn list_error_python(bench: &mut Bencher) {
212
212
213
213
#[ bench]
214
214
fn list_error_python_isinstance ( bench : & mut Bencher ) {
215
- Python :: with_gil ( |py| {
215
+ Python :: attach ( |py| {
216
216
let ( validator, input) = list_error_python_input ( py) ;
217
217
let input = black_box ( input. bind ( py) ) ;
218
218
let r = validator
@@ -232,7 +232,7 @@ fn list_error_python_isinstance(bench: &mut Bencher) {
232
232
233
233
#[ bench]
234
234
fn list_any_json ( bench : & mut Bencher ) {
235
- Python :: with_gil ( |py| {
235
+ Python :: attach ( |py| {
236
236
let validator = build_schema_validator ( py, c"{'type': 'list'}" ) ;
237
237
let code = format ! (
238
238
"[{}]" ,
@@ -251,7 +251,7 @@ fn list_any_json(bench: &mut Bencher) {
251
251
252
252
#[ bench]
253
253
fn list_any_python ( bench : & mut Bencher ) {
254
- Python :: with_gil ( |py| {
254
+ Python :: attach ( |py| {
255
255
let validator = build_schema_validator ( py, c"{'type': 'list'}" ) ;
256
256
let code = CString :: new ( format ! (
257
257
"[{}]" ,
@@ -279,7 +279,7 @@ fn as_str(i: u8) -> String {
279
279
280
280
#[ bench]
281
281
fn dict_json ( bench : & mut Bencher ) {
282
- Python :: with_gil ( |py| {
282
+ Python :: attach ( |py| {
283
283
let validator = build_schema_validator (
284
284
py,
285
285
c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}" ,
@@ -305,7 +305,7 @@ fn dict_json(bench: &mut Bencher) {
305
305
306
306
#[ bench]
307
307
fn dict_python ( bench : & mut Bencher ) {
308
- Python :: with_gil ( |py| {
308
+ Python :: attach ( |py| {
309
309
let validator = build_schema_validator (
310
310
py,
311
311
c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}" ,
@@ -332,7 +332,7 @@ fn dict_python(bench: &mut Bencher) {
332
332
333
333
#[ bench]
334
334
fn dict_value_error ( bench : & mut Bencher ) {
335
- Python :: with_gil ( |py| {
335
+ Python :: attach ( |py| {
336
336
let validator = build_schema_validator (
337
337
py,
338
338
cr"{
@@ -378,7 +378,7 @@ fn dict_value_error(bench: &mut Bencher) {
378
378
379
379
#[ bench]
380
380
fn typed_dict_json ( bench : & mut Bencher ) {
381
- Python :: with_gil ( |py| {
381
+ Python :: attach ( |py| {
382
382
let validator = build_schema_validator (
383
383
py,
384
384
cr"{
@@ -413,7 +413,7 @@ fn typed_dict_json(bench: &mut Bencher) {
413
413
414
414
#[ bench]
415
415
fn typed_dict_python ( bench : & mut Bencher ) {
416
- Python :: with_gil ( |py| {
416
+ Python :: attach ( |py| {
417
417
let validator = build_schema_validator (
418
418
py,
419
419
cr"{
@@ -448,7 +448,7 @@ fn typed_dict_python(bench: &mut Bencher) {
448
448
449
449
#[ bench]
450
450
fn typed_dict_deep_error ( bench : & mut Bencher ) {
451
- Python :: with_gil ( |py| {
451
+ Python :: attach ( |py| {
452
452
let validator = build_schema_validator (
453
453
py,
454
454
cr"{
@@ -504,7 +504,7 @@ fn typed_dict_deep_error(bench: &mut Bencher) {
504
504
505
505
#[ bench]
506
506
fn complete_model ( bench : & mut Bencher ) {
507
- Python :: with_gil ( |py| {
507
+ Python :: attach ( |py| {
508
508
let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
509
509
sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
510
510
@@ -527,7 +527,7 @@ fn complete_model(bench: &mut Bencher) {
527
527
528
528
#[ bench]
529
529
fn nested_model_using_definitions ( bench : & mut Bencher ) {
530
- Python :: with_gil ( |py| {
530
+ Python :: attach ( |py| {
531
531
let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
532
532
sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
533
533
@@ -554,7 +554,7 @@ fn nested_model_using_definitions(bench: &mut Bencher) {
554
554
555
555
#[ bench]
556
556
fn nested_model_inlined ( bench : & mut Bencher ) {
557
- Python :: with_gil ( |py| {
557
+ Python :: attach ( |py| {
558
558
let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
559
559
sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
560
560
@@ -581,7 +581,7 @@ fn nested_model_inlined(bench: &mut Bencher) {
581
581
582
582
#[ bench]
583
583
fn literal_ints_few_python ( bench : & mut Bencher ) {
584
- Python :: with_gil ( |py| {
584
+ Python :: attach ( |py| {
585
585
let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(5))}" ) ;
586
586
587
587
let Ok ( input) = 4_i64 . into_pyobject ( py) ;
@@ -604,7 +604,7 @@ fn literal_ints_few_python(bench: &mut Bencher) {
604
604
605
605
#[ bench]
606
606
fn literal_strings_few_small_python ( bench : & mut Bencher ) {
607
- Python :: with_gil ( |py| {
607
+ Python :: attach ( |py| {
608
608
let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(5)]}" ) ;
609
609
610
610
let input = py. eval ( c"'4'" , None , None ) . unwrap ( ) ;
@@ -628,7 +628,7 @@ fn literal_strings_few_small_python(bench: &mut Bencher) {
628
628
629
629
#[ bench]
630
630
fn literal_strings_few_large_python ( bench : & mut Bencher ) {
631
- Python :: with_gil ( |py| {
631
+ Python :: attach ( |py| {
632
632
let validator = build_schema_validator (
633
633
py,
634
634
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(5)]}" ,
@@ -655,7 +655,7 @@ fn literal_strings_few_large_python(bench: &mut Bencher) {
655
655
656
656
#[ bench]
657
657
fn literal_enums_few_python ( bench : & mut Bencher ) {
658
- Python :: with_gil ( |py| {
658
+ Python :: attach ( |py| {
659
659
let globals = PyDict :: new ( py) ;
660
660
py. run (
661
661
cr"
@@ -697,7 +697,7 @@ class Foo(Enum):
697
697
698
698
#[ bench]
699
699
fn literal_ints_many_python ( bench : & mut Bencher ) {
700
- Python :: with_gil ( |py| {
700
+ Python :: attach ( |py| {
701
701
let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(100))}" ) ;
702
702
703
703
let Ok ( input) = 99_i64 . into_pyobject ( py) ;
@@ -720,7 +720,7 @@ fn literal_ints_many_python(bench: &mut Bencher) {
720
720
721
721
#[ bench]
722
722
fn literal_strings_many_small_python ( bench : & mut Bencher ) {
723
- Python :: with_gil ( |py| {
723
+ Python :: attach ( |py| {
724
724
let validator =
725
725
build_schema_validator ( py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(100)]}" ) ;
726
726
@@ -745,7 +745,7 @@ fn literal_strings_many_small_python(bench: &mut Bencher) {
745
745
746
746
#[ bench]
747
747
fn literal_strings_many_large_python ( bench : & mut Bencher ) {
748
- Python :: with_gil ( |py| {
748
+ Python :: attach ( |py| {
749
749
let validator = build_schema_validator (
750
750
py,
751
751
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}" ,
@@ -772,7 +772,7 @@ fn literal_strings_many_large_python(bench: &mut Bencher) {
772
772
773
773
#[ bench]
774
774
fn literal_ints_many_json ( bench : & mut Bencher ) {
775
- Python :: with_gil ( |py| {
775
+ Python :: attach ( |py| {
776
776
let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(100))}" ) ;
777
777
778
778
let input_json = py. eval ( c"'99'" , None , None ) . unwrap ( ) ;
@@ -795,7 +795,7 @@ fn literal_ints_many_json(bench: &mut Bencher) {
795
795
796
796
#[ bench]
797
797
fn literal_strings_many_large_json ( bench : & mut Bencher ) {
798
- Python :: with_gil ( |py| {
798
+ Python :: attach ( |py| {
799
799
let validator = build_schema_validator (
800
800
py,
801
801
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}" ,
@@ -823,7 +823,7 @@ fn literal_strings_many_large_json(bench: &mut Bencher) {
823
823
824
824
#[ bench]
825
825
fn literal_mixed_few_python ( bench : & mut Bencher ) {
826
- Python :: with_gil ( |py| {
826
+ Python :: attach ( |py| {
827
827
let globals = PyDict :: new ( py) ;
828
828
py. run (
829
829
cr"
0 commit comments