Skip to content

Commit 7818fd2

Browse files
committed
Fix micro benchmarks
1 parent eb22ba1 commit 7818fd2

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

benches/microbenchmarks.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use criterion::{
66
use rustpython_compiler::Mode;
77
use rustpython_vm::pyobject::ItemProtocol;
88
use rustpython_vm::pyobject::PyResult;
9-
use rustpython_vm::Interpreter;
9+
use rustpython_vm::{InitParameter, Interpreter, PySettings};
1010
use std::path::{Path, PathBuf};
1111
use std::{fs, io};
1212

@@ -16,19 +16,6 @@ pub struct MicroBenchmark {
1616
code: String,
1717
iterate: bool,
1818
}
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-
// }
3219

3320
fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchmark) {
3421
let gil = cpython::Python::acquire_gil();
@@ -78,7 +65,12 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
7865
}
7966

8067
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| {
8274
let setup_code = vm
8375
.compile(&bench.setup, Mode::Exec, bench.name.to_owned())
8476
.expect("Error compiling setup code");
@@ -99,8 +91,8 @@ fn bench_rustpy_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchmar
9991
.set_item(vm.ctx.new_str("ITERATIONS"), vm.ctx.new_int(idx), vm)
10092
.expect("Error adding ITERATIONS local variable");
10193
}
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);
10496
(scope, bench_code.clone())
10597
};
10698

0 commit comments

Comments
 (0)