Skip to content

Commit e0c812d

Browse files
morealclaude
andcommitted
Use stdlib native modules in benchmarks
Change benchmark interpreter from without_stdlib to with_init to load Rust-optimized native modules like _json, ensuring benchmarks measure actual optimized performance rather than pure Python fallbacks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 00440b1 commit e0c812d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ rustyline = { workspace = true }
5454
[dev-dependencies]
5555
criterion = { workspace = true }
5656
pyo3 = { version = "0.27", features = ["auto-initialize"] }
57+
rustpython-stdlib = { workspace = true }
5758

5859
[[bench]]
5960
name = "execution"

benches/execution.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use criterion::{
33
measurement::WallTime,
44
};
55
use rustpython_compiler::Mode;
6+
use rustpython_stdlib;
67
use rustpython_vm::{Interpreter, PyResult, Settings};
78
use std::{collections::HashMap, hint::black_box, path::Path};
89

@@ -24,7 +25,10 @@ fn bench_rustpython_code(b: &mut Bencher, name: &str, source: &str) {
2425
settings.path_list.push("Lib/".to_string());
2526
settings.write_bytecode = false;
2627
settings.user_site_directory = false;
27-
Interpreter::without_stdlib(settings).enter(|vm| {
28+
Interpreter::with_init(settings, |vm| {
29+
vm.add_native_modules(rustpython_stdlib::get_module_inits());
30+
})
31+
.enter(|vm| {
2832
// Note: bench_cpython is both compiling and executing the code.
2933
// As such we compile the code in the benchmark loop as well.
3034
b.iter(|| {

0 commit comments

Comments
 (0)