@@ -2,6 +2,7 @@ use criterion::{
22 criterion_group, criterion_main, measurement:: WallTime , BatchSize , BenchmarkGroup , BenchmarkId ,
33 Criterion , Throughput ,
44} ;
5+ use pyo3:: types:: PyAnyMethods ;
56use rustpython_compiler:: Mode ;
67use rustpython_vm:: { AsObject , Interpreter , PyResult , Settings } ;
78use std:: {
@@ -44,25 +45,28 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
4445
4546 // Grab the exec function in advance so we don't have lookups in the hot code
4647 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" ) ;
4849 let exec = builtins. getattr ( "exec" ) . expect ( "no exec in builtins" ) ;
4950
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 ) ;
5256 if let Err ( e) = res {
5357 e. print ( py) ;
5458 panic ! ( "Error running microbenchmark" )
5559 }
5660 } ;
5761
5862 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) ;
6165 if let Some ( idx) = iterations {
6266 globals. set_item ( "ITERATIONS" , idx) . unwrap ( ) ;
6367 }
6468
65- let res = exec. call ( ( setup_code, & globals, & locals) , None ) ;
69+ let res = exec. call ( ( & setup_code, & globals, & locals) , None ) ;
6670 if let Err ( e) = res {
6771 e. print ( py) ;
6872 panic ! ( "Error running microbenchmark setup code" )
@@ -93,9 +97,9 @@ fn cpy_compile_code<'a>(
9397 py : pyo3:: Python < ' a > ,
9498 code : & str ,
9599 name : & str ,
96- ) -> pyo3:: PyResult < & ' a pyo3:: types:: PyCode > {
100+ ) -> pyo3:: PyResult < pyo3 :: Bound < ' a , pyo3:: types:: PyCode > > {
97101 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" ) ;
99103 let compile = builtins. getattr ( "compile" ) . expect ( "no compile in builtins" ) ;
100104 compile. call1 ( ( code, name, "exec" ) ) ?. extract ( )
101105}
0 commit comments