| 48 | } |
| 49 | |
| 50 | pub fn benchmark_file_parsing(group: &mut BenchmarkGroup<WallTime>, name: &str, contents: &str) { |
| 51 | group.throughput(Throughput::Bytes(contents.len() as u64)); |
| 52 | group.bench_function(BenchmarkId::new("rustpython", name), |b| { |
| 53 | b.iter(|| ruff_python_parser::parse_module(contents).unwrap()) |
| 54 | }); |
| 55 | group.bench_function(BenchmarkId::new("cpython", name), |b| { |
| 56 | use pyo3::types::PyAnyMethods; |
| 57 | pyo3::Python::attach(|py| { |
| 58 | let builtins = |
| 59 | pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins"); |
| 60 | let compile = builtins.getattr("compile").expect("no compile in builtins"); |
| 61 | b.iter(|| { |
| 62 | let x = compile |
| 63 | .call1((contents, name, "exec")) |
| 64 | .expect("Failed to parse code"); |
| 65 | black_box(x); |
| 66 | }) |
| 67 | }) |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | pub fn benchmark_pystone(group: &mut BenchmarkGroup<WallTime>, contents: String) { |
| 72 | // Default is 50_000. This takes a while, so reduce it to 30k. |