[red-knot] update benchmark to run on tomllib (#12635)

Changes the red-knot benchmark to run on the stdlib "tomllib" library
(which is self-contained, four files, uses type annotations) instead of
on very small bits of handwritten code.

Also remove the `without_parse` benchmark: now that we are running on
real code that uses typeshed, we'd either have to pre-parse all of
typeshed (slow) or find some way to determine which typeshed modules
will be used by the benchmark (not feasible with reasonable complexity.)

## Test Plan

`cargo bench -p ruff_benchmark --bench red_knot`
This commit is contained in:
Carl Meyer 2024-08-02 11:23:52 -07:00 committed by GitHub
parent 12177a42e3
commit 1c311e4fdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 98 deletions

View file

@ -70,6 +70,16 @@ pub struct TestFile {
code: String,
}
impl TestFile {
pub fn code(&self) -> &str {
&self.code
}
pub fn name(&self) -> &str {
&self.name
}
}
static TARGET_DIR: once_cell::sync::Lazy<PathBuf> = once_cell::sync::Lazy::new(|| {
cargo_target_directory().unwrap_or_else(|| PathBuf::from("target"))
});
@ -114,7 +124,7 @@ impl TestFile {
// SAFETY: There's always the `target` directory
let parent = cached_filename.parent().unwrap();
if let Err(error) = std::fs::create_dir_all(parent) {
eprintln!("Failed to crate the directory for the test case {name}: {error}");
eprintln!("Failed to create the directory for the test case {name}: {error}");
} else if let Err(error) = std::fs::write(cached_filename, &content) {
eprintln!("Failed to cache test case file downloaded from {url}: {error}");
}