chore: clippy
This commit is contained in:
parent
a1870b6013
commit
c8bd6705cf
36 changed files with 467 additions and 462 deletions
|
|
@ -15,7 +15,7 @@ lazy_static! {
|
|||
static ref EXAMPLE_FILTER: Option<String> =
|
||||
env::var("TREE_SITTER_BENCHMARK_EXAMPLE_FILTER").ok();
|
||||
static ref REPETITION_COUNT: usize = env::var("TREE_SITTER_BENCHMARK_REPETITION_COUNT")
|
||||
.map(|s| usize::from_str_radix(&s, 10).unwrap())
|
||||
.map(|s| s.parse::<usize>().unwrap())
|
||||
.unwrap_or(5);
|
||||
static ref TEST_LOADER: Loader = Loader::with_parser_lib_path(SCRATCH_DIR.clone());
|
||||
static ref EXAMPLE_AND_QUERY_PATHS_BY_LANGUAGE_DIR: BTreeMap<PathBuf, (Vec<PathBuf>, Vec<PathBuf>)> = {
|
||||
|
|
@ -29,7 +29,7 @@ lazy_static! {
|
|||
example_paths.extend(example_files.filter_map(|p| {
|
||||
let p = p.unwrap().path();
|
||||
if p.is_file() {
|
||||
Some(p.to_owned())
|
||||
Some(p)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ lazy_static! {
|
|||
query_paths.extend(query_files.filter_map(|p| {
|
||||
let p = p.unwrap().path();
|
||||
if p.is_file() {
|
||||
Some(p.to_owned())
|
||||
Some(p)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
eprintln!("\nLanguage: {}", language_name);
|
||||
eprintln!("\nLanguage: {language_name}");
|
||||
let language = get_language(language_path);
|
||||
parser.set_language(&language).unwrap();
|
||||
|
||||
|
|
@ -144,13 +144,13 @@ fn main() {
|
|||
}
|
||||
|
||||
if let Some((average_normal, worst_normal)) = aggregate(&normal_speeds) {
|
||||
eprintln!(" Average Speed (normal): {} bytes/ms", average_normal);
|
||||
eprintln!(" Worst Speed (normal): {} bytes/ms", worst_normal);
|
||||
eprintln!(" Average Speed (normal): {average_normal} bytes/ms");
|
||||
eprintln!(" Worst Speed (normal): {worst_normal} bytes/ms");
|
||||
}
|
||||
|
||||
if let Some((average_error, worst_error)) = aggregate(&error_speeds) {
|
||||
eprintln!(" Average Speed (errors): {} bytes/ms", average_error);
|
||||
eprintln!(" Worst Speed (errors): {} bytes/ms", worst_error);
|
||||
eprintln!(" Average Speed (errors): {average_error} bytes/ms");
|
||||
eprintln!(" Worst Speed (errors): {worst_error} bytes/ms");
|
||||
}
|
||||
|
||||
all_normal_speeds.extend(normal_speeds);
|
||||
|
|
@ -159,24 +159,24 @@ fn main() {
|
|||
|
||||
eprintln!("\n Overall");
|
||||
if let Some((average_normal, worst_normal)) = aggregate(&all_normal_speeds) {
|
||||
eprintln!(" Average Speed (normal): {} bytes/ms", average_normal);
|
||||
eprintln!(" Worst Speed (normal): {} bytes/ms", worst_normal);
|
||||
eprintln!(" Average Speed (normal): {average_normal} bytes/ms");
|
||||
eprintln!(" Worst Speed (normal): {worst_normal} bytes/ms");
|
||||
}
|
||||
|
||||
if let Some((average_error, worst_error)) = aggregate(&all_error_speeds) {
|
||||
eprintln!(" Average Speed (errors): {} bytes/ms", average_error);
|
||||
eprintln!(" Worst Speed (errors): {} bytes/ms", worst_error);
|
||||
eprintln!(" Average Speed (errors): {average_error} bytes/ms");
|
||||
eprintln!(" Worst Speed (errors): {worst_error} bytes/ms");
|
||||
}
|
||||
eprintln!();
|
||||
}
|
||||
|
||||
fn aggregate(speeds: &Vec<usize>) -> Option<(usize, usize)> {
|
||||
fn aggregate(speeds: &[usize]) -> Option<(usize, usize)> {
|
||||
if speeds.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut total = 0;
|
||||
let mut max = usize::MAX;
|
||||
for speed in speeds.iter().cloned() {
|
||||
for speed in speeds.iter().copied() {
|
||||
total += speed;
|
||||
if speed < max {
|
||||
max = speed;
|
||||
|
|
@ -193,7 +193,7 @@ fn parse(path: &Path, max_path_length: usize, mut action: impl FnMut(&[u8])) ->
|
|||
);
|
||||
|
||||
let source_code = fs::read(path)
|
||||
.with_context(|| format!("Failed to read {:?}", path))
|
||||
.with_context(|| format!("Failed to read {path:?}"))
|
||||
.unwrap();
|
||||
let time = Instant::now();
|
||||
for _ in 0..*REPETITION_COUNT {
|
||||
|
|
@ -202,7 +202,7 @@ fn parse(path: &Path, max_path_length: usize, mut action: impl FnMut(&[u8])) ->
|
|||
let duration = time.elapsed() / (*REPETITION_COUNT as u32);
|
||||
let duration_ms = duration.as_millis();
|
||||
let speed = source_code.len() as u128 / (duration_ms + 1);
|
||||
eprintln!("time {} ms\tspeed {} bytes/ms", duration_ms as usize, speed);
|
||||
eprintln!("time {} ms\tspeed {speed} bytes/ms", duration_ms as usize);
|
||||
speed as usize
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +210,6 @@ fn get_language(path: &Path) -> Language {
|
|||
let src_dir = GRAMMARS_DIR.join(path).join("src");
|
||||
TEST_LOADER
|
||||
.load_language_at_path(&src_dir, &[&src_dir])
|
||||
.with_context(|| format!("Failed to load language at path {:?}", src_dir))
|
||||
.with_context(|| format!("Failed to load language at path {src_dir:?}"))
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue