@@ -2,6 +2,7 @@ use criterion::{
2
2
criterion_group, criterion_main, measurement:: WallTime , BatchSize , BenchmarkGroup , BenchmarkId ,
3
3
Criterion , Throughput ,
4
4
} ;
5
+ use pyo3:: types:: PyAnyMethods ;
5
6
use rustpython_compiler:: Mode ;
6
7
use rustpython_vm:: { AsObject , Interpreter , PyResult , Settings } ;
7
8
use std:: {
@@ -44,25 +45,28 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
44
45
45
46
// Grab the exec function in advance so we don't have lookups in the hot code
46
47
let builtins =
47
- pyo3:: types:: PyModule :: import ( py, "builtins" ) . expect ( "Failed to import builtins" ) ;
48
+ pyo3:: types:: PyModule :: import_bound ( py, "builtins" ) . expect ( "Failed to import builtins" ) ;
48
49
let exec = builtins. getattr ( "exec" ) . expect ( "no exec in builtins" ) ;
49
50
50
- let bench_func = |( globals, locals) : & mut ( & pyo3:: types:: PyDict , & pyo3:: types:: PyDict ) | {
51
- let res = exec. call ( ( code, & * globals, & * locals) , None ) ;
51
+ let bench_func = |( globals, locals) : & mut (
52
+ pyo3:: Bound < pyo3:: types:: PyDict > ,
53
+ pyo3:: Bound < pyo3:: types:: PyDict > ,
54
+ ) | {
55
+ let res = exec. call ( ( & code, & * globals, & * locals) , None ) ;
52
56
if let Err ( e) = res {
53
57
e. print ( py) ;
54
58
panic ! ( "Error running microbenchmark" )
55
59
}
56
60
} ;
57
61
58
62
let bench_setup = |iterations| {
59
- let globals = pyo3:: types:: PyDict :: new ( py) ;
60
- let locals = pyo3:: types:: PyDict :: new ( py) ;
63
+ let globals = pyo3:: types:: PyDict :: new_bound ( py) ;
64
+ let locals = pyo3:: types:: PyDict :: new_bound ( py) ;
61
65
if let Some ( idx) = iterations {
62
66
globals. set_item ( "ITERATIONS" , idx) . unwrap ( ) ;
63
67
}
64
68
65
- let res = exec. call ( ( setup_code, & globals, & locals) , None ) ;
69
+ let res = exec. call ( ( & setup_code, & globals, & locals) , None ) ;
66
70
if let Err ( e) = res {
67
71
e. print ( py) ;
68
72
panic ! ( "Error running microbenchmark setup code" )
@@ -93,9 +97,9 @@ fn cpy_compile_code<'a>(
93
97
py : pyo3:: Python < ' a > ,
94
98
code : & str ,
95
99
name : & str ,
96
- ) -> pyo3:: PyResult < & ' a pyo3:: types:: PyCode > {
100
+ ) -> pyo3:: PyResult < pyo3 :: Bound < ' a , pyo3:: types:: PyCode > > {
97
101
let builtins =
98
- pyo3:: types:: PyModule :: import ( py, "builtins" ) . expect ( "Failed to import builtins" ) ;
102
+ pyo3:: types:: PyModule :: import_bound ( py, "builtins" ) . expect ( "Failed to import builtins" ) ;
99
103
let compile = builtins. getattr ( "compile" ) . expect ( "no compile in builtins" ) ;
100
104
compile. call1 ( ( code, name, "exec" ) ) ?. extract ( )
101
105
}
0 commit comments