@@ -6,7 +6,7 @@ use criterion::{
6
6
use rustpython_compiler:: Mode ;
7
7
use rustpython_vm:: pyobject:: ItemProtocol ;
8
8
use rustpython_vm:: pyobject:: PyResult ;
9
- use rustpython_vm:: Interpreter ;
9
+ use rustpython_vm:: { InitParameter , Interpreter , PySettings } ;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
use std:: { fs, io} ;
12
12
@@ -16,19 +16,6 @@ pub struct MicroBenchmark {
16
16
code : String ,
17
17
iterate : bool ,
18
18
}
19
- //
20
- // fn bench_cpython_code(b: &mut Bencher, source: &str) {
21
- // let gil = cpython::Python::acquire_gil();
22
- // let python = gil.python();
23
- //
24
- // b.iter(|| {
25
- // let res: cpython::PyResult<()> = python.run(source, None, None);
26
- // if let Err(e) = res {
27
- // e.print(python);
28
- // panic!("Error running source")
29
- // }
30
- // });
31
- // }
32
19
33
20
fn bench_cpython_code ( group : & mut BenchmarkGroup < WallTime > , bench : & MicroBenchmark ) {
34
21
let gil = cpython:: Python :: acquire_gil ( ) ;
@@ -78,7 +65,12 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
78
65
}
79
66
80
67
fn bench_rustpy_code ( group : & mut BenchmarkGroup < WallTime > , bench : & MicroBenchmark ) {
81
- Interpreter :: default ( ) . enter ( |vm| {
68
+ let mut settings = PySettings :: default ( ) ;
69
+ settings. path_list . push ( "Lib/" . to_string ( ) ) ;
70
+ settings. dont_write_bytecode = true ;
71
+ settings. no_user_site = true ;
72
+
73
+ Interpreter :: new ( settings, InitParameter :: External ) . enter ( |vm| {
82
74
let setup_code = vm
83
75
. compile ( & bench. setup , Mode :: Exec , bench. name . to_owned ( ) )
84
76
. expect ( "Error compiling setup code" ) ;
@@ -99,8 +91,8 @@ fn bench_rustpy_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchmar
99
91
. set_item ( vm. ctx . new_str ( "ITERATIONS" ) , vm. ctx . new_int ( idx) , vm)
100
92
. expect ( "Error adding ITERATIONS local variable" ) ;
101
93
}
102
- vm. run_code_obj ( setup_code. clone ( ) , scope. clone ( ) )
103
- . expect ( "Error running benchmark setup code" ) ;
94
+ let setup_result = vm. run_code_obj ( setup_code. clone ( ) , scope. clone ( ) ) ;
95
+ vm . unwrap_pyresult ( setup_result ) ;
104
96
( scope, bench_code. clone ( ) )
105
97
} ;
106
98
0 commit comments