(b: &mut Bencher, name: &str, source: &str)
| 19 | } |
| 20 | |
| 21 | fn 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 | |
| 41 | pub fn benchmark_file_execution(group: &mut BenchmarkGroup<WallTime>, name: &str, contents: &str) { |
| 42 | group.bench_function(BenchmarkId::new(name, "cpython"), |b| { |
no test coverage detected