MCPcopy Index your code
hub / github.com/RustPython/RustPython / bench_rustpython_code

Function bench_rustpython_code

benches/execution.rs:21–39  ·  view source on GitHub ↗
(b: &mut Bencher, name: &str, source: &str)

Source from the content-addressed store, hash-verified

19}
20
21fn bench_rustpython_code(b: &mut Bencher, name: &str, source: &str) {
22 // NOTE: Take long time.
23 let mut settings = Settings::default();
24 settings.path_list.push("Lib/".to_string());
25 settings.write_bytecode = false;
26 settings.user_site_directory = false;
27 let builder = Interpreter::builder(settings);
28 let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx);
29 builder.add_native_modules(&defs).build().enter(|vm| {
30 // Note: bench_cpython is both compiling and executing the code.
31 // As such we compile the code in the benchmark loop as well.
32 b.iter(|| {
33 let code = vm.compile(source, Mode::Exec, name.to_owned()).unwrap();
34 let scope = vm.new_scope_with_builtins();
35 let res: PyResult = vm.run_code_obj(code.clone(), scope);
36 vm.unwrap_pyresult(res);
37 })
38 })
39}
40
41pub fn benchmark_file_execution(group: &mut BenchmarkGroup<WallTime>, name: &str, contents: &str) {
42 group.bench_function(BenchmarkId::new(name, "cpython"), |b| {

Callers 2

benchmark_file_executionFunction · 0.70
benchmark_pystoneFunction · 0.70

Calls 14

stdlib_module_defsFunction · 0.85
to_stringMethod · 0.80
add_native_modulesMethod · 0.80
run_code_objMethod · 0.80
unwrap_pyresultMethod · 0.80
pushMethod · 0.45
enterMethod · 0.45
buildMethod · 0.45
iterMethod · 0.45
unwrapMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected