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

Function benchmark_file_parsing

benches/execution.rs:50–69  ·  view source on GitHub ↗
(group: &mut BenchmarkGroup<WallTime>, name: &str, contents: &str)

Source from the content-addressed store, hash-verified

48}
49
50pub 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
71pub fn benchmark_pystone(group: &mut BenchmarkGroup<WallTime>, contents: String) {
72 // Default is 50_000. This takes a while, so reduce it to 30k.

Callers 1

criterion_benchmarkFunction · 0.85

Calls 5

BytesClass · 0.85
newFunction · 0.85
lenMethod · 0.45
iterMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected