Skip to content

Commit

Permalink
[red-knot] preparse builtins in without_parse benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Jul 18, 2024
1 parent fa5b19d commit 93cf6b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/ruff_benchmark/benches/red_knot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use red_knot::workspace::WorkspaceMetadata;
use ruff_benchmark::criterion::{
criterion_group, criterion_main, BatchSize, Criterion, Throughput,
};
use ruff_db::files::{system_path_to_file, File};
use ruff_db::files::{system_path_to_file, vendored_path_to_file, File};
use ruff_db::parsed::parsed_module;
use ruff_db::program::{ProgramSettings, SearchPathSettings, TargetVersion};
use ruff_db::system::{MemoryFileSystem, SystemPath, TestSystem};
use ruff_db::vendored::VendoredPath;
use ruff_db::Upcast;

static FOO_CODE: &str = r#"
Expand Down Expand Up @@ -48,6 +49,7 @@ struct Case {
foo: File,
bar: File,
typing: File,
builtins: File,
}

fn setup_case() -> Case {
Expand All @@ -56,6 +58,7 @@ fn setup_case() -> Case {
let foo_path = SystemPath::new("/src/foo.py");
let bar_path = SystemPath::new("/src/bar.py");
let typing_path = SystemPath::new("/src/typing.pyi");
let builtins_path = VendoredPath::new("stdlib/builtins.pyi");
fs.write_files([
(foo_path, FOO_CODE),
(bar_path, BAR_CODE),
Expand All @@ -82,13 +85,15 @@ fn setup_case() -> Case {

let bar = system_path_to_file(&db, bar_path).unwrap();
let typing = system_path_to_file(&db, typing_path).unwrap();
let builtins = vendored_path_to_file(&db, builtins_path).unwrap();

Case {
db,
fs,
foo,
bar,
typing,
builtins,
}
}

Expand All @@ -104,6 +109,7 @@ fn benchmark_without_parse(criterion: &mut Criterion) {
parsed_module(case.db.upcast(), case.foo);
parsed_module(case.db.upcast(), case.bar);
parsed_module(case.db.upcast(), case.typing);
parsed_module(case.db.upcast(), case.builtins);
case
},
|case| {
Expand Down

0 comments on commit 93cf6b5

Please sign in to comment.