Skip to content

Commit

Permalink
perf: Multi-threaded spell checking
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
Ed Page authored and epage committed Oct 28, 2019
1 parent 319a991 commit a24cda7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
6 changes: 5 additions & 1 deletion benchsuite/benchsuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ function bench_dir() {
echo "$name: $version" >> $output
echo "" >> $output
rg_command=""
rg_j1_command=""
if [[ ! -z $rg_path ]]; then
rg_command="$rg_path bin $path"
rg_j1_command="$rg_path --threads 1 bin $path"
fi
typos_command=""
typos_j1_command=""
if [[ ! -z $typos_path ]]; then
typos_command="$typos_path $path"
typos_j1_command="$typos_path --threads 1 $path"
fi
misspell_rs_command=""
if [[ ! -z $misspell_rs_path ]]; then
Expand All @@ -110,7 +114,7 @@ function bench_dir() {
if [[ ! -z $codespell_path ]]; then
codespell_command="$codespell_path $path"
fi
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$rg_j1_command" "$typos_command" "$typos_j1_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
cat $report_prefix-rg.md >> $output
fi
echo "" >> $output
Expand Down
33 changes: 25 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,33 @@ fn run() -> Result<i32, failure::Error> {
.git_ignore(config.files.ignore_vcs())
.git_exclude(config.files.ignore_vcs())
.parents(config.files.ignore_parent());
for entry in walk.build() {
match check_entry(entry, &args, &checks) {
Ok(true) => typos_found = true,
Err(err) => {
let msg = typos::report::Error::new(err.to_string());
args.format.report()(msg.into());
errors_found = true
if args.threads == 1 {
for entry in walk.build() {
match check_entry(entry, &args, &checks) {
Ok(true) => typos_found = true,
Err(err) => {
let msg = typos::report::Error::new(err.to_string());
args.format.report()(msg.into());
errors_found = true
}
_ => (),
}
_ => (),
}
} else {
walk.build_parallel().run(|| {
Box::new(|entry: Result<ignore::DirEntry, ignore::Error>| {
match check_entry(entry, &args, &checks) {
Ok(true) => typos_found = true,
Err(err) => {
let msg = typos::report::Error::new(err.to_string());
args.format.report()(msg.into());
errors_found = true
}
_ => (),
}
ignore::WalkState::Continue
})
});
}
}

Expand Down

0 comments on commit a24cda7

Please sign in to comment.