From c3180e3107314932cb7622117f1e7ddfaa1ca430 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Mon, 19 Jan 2026 05:02:22 +0900 Subject: [PATCH] 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 --- Cargo.toml | 1 + benches/execution.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 083358cf749..6c29f67e03b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ rustyline = { workspace = true } [dev-dependencies] criterion = { workspace = true } pyo3 = { version = "0.27", features = ["auto-initialize"] } +rustpython-stdlib = { workspace = true } [[bench]] name = "execution" diff --git a/benches/execution.rs b/benches/execution.rs index c2239b59d12..bf1bcfcc3db 100644 --- a/benches/execution.rs +++ b/benches/execution.rs @@ -24,7 +24,10 @@ fn bench_rustpython_code(b: &mut Bencher, name: &str, source: &str) { settings.path_list.push("Lib/".to_string()); settings.write_bytecode = false; settings.user_site_directory = false; - Interpreter::without_stdlib(settings).enter(|vm| { + Interpreter::with_init(settings, |vm| { + vm.add_native_modules(rustpython_stdlib::get_module_inits()); + }) + .enter(|vm| { // Note: bench_cpython is both compiling and executing the code. // As such we compile the code in the benchmark loop as well. b.iter(|| {