-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #928 from epage/divan
test(bench): Switch to Divan
- Loading branch information
Showing
8 changed files
with
411 additions
and
515 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
mod data; | ||
|
||
use assert_fs::prelude::*; | ||
use typos_cli::file::FileChecker; | ||
|
||
#[divan::bench(args = data::DATA)] | ||
fn found_files(bencher: divan::Bencher, sample: &data::Data) { | ||
let dict = typos_cli::dict::BuiltIn::new(Default::default()); | ||
let tokenizer = typos::tokens::Tokenizer::new(); | ||
let policy = typos_cli::policy::Policy::new() | ||
.dict(&dict) | ||
.tokenizer(&tokenizer); | ||
|
||
let temp = assert_fs::TempDir::new().unwrap(); | ||
let sample_path = temp.child(sample.name()); | ||
sample_path.write_str(sample.content()).unwrap(); | ||
|
||
bencher | ||
.counter(divan::counter::BytesCount::of_str(sample.content())) | ||
.bench_local(|| { | ||
typos_cli::file::FoundFiles.check_file(sample_path.path(), true, &policy, &PrintSilent) | ||
}) | ||
} | ||
|
||
#[divan::bench(args = data::DATA)] | ||
fn identifiers(bencher: divan::Bencher, sample: &data::Data) { | ||
let dict = typos_cli::dict::BuiltIn::new(Default::default()); | ||
let tokenizer = typos::tokens::Tokenizer::new(); | ||
let policy = typos_cli::policy::Policy::new() | ||
.dict(&dict) | ||
.tokenizer(&tokenizer); | ||
|
||
let temp = assert_fs::TempDir::new().unwrap(); | ||
let sample_path = temp.child(sample.name()); | ||
sample_path.write_str(sample.content()).unwrap(); | ||
|
||
bencher | ||
.counter(divan::counter::BytesCount::of_str(sample.content())) | ||
.bench_local(|| { | ||
typos_cli::file::Identifiers.check_file(sample_path.path(), true, &policy, &PrintSilent) | ||
}) | ||
} | ||
|
||
#[divan::bench(args = data::DATA)] | ||
fn words(bencher: divan::Bencher, sample: &data::Data) { | ||
let dict = typos_cli::dict::BuiltIn::new(Default::default()); | ||
let tokenizer = typos::tokens::Tokenizer::new(); | ||
let policy = typos_cli::policy::Policy::new() | ||
.dict(&dict) | ||
.tokenizer(&tokenizer); | ||
|
||
let temp = assert_fs::TempDir::new().unwrap(); | ||
let sample_path = temp.child(sample.name()); | ||
sample_path.write_str(sample.content()).unwrap(); | ||
|
||
bencher | ||
.counter(divan::counter::BytesCount::of_str(sample.content())) | ||
.bench_local(|| { | ||
typos_cli::file::Words.check_file(sample_path.path(), true, &policy, &PrintSilent) | ||
}) | ||
} | ||
|
||
#[divan::bench(args = data::DATA)] | ||
fn typos(bencher: divan::Bencher, sample: &data::Data) { | ||
let dict = typos_cli::dict::BuiltIn::new(Default::default()); | ||
let tokenizer = typos::tokens::Tokenizer::new(); | ||
let policy = typos_cli::policy::Policy::new() | ||
.dict(&dict) | ||
.tokenizer(&tokenizer); | ||
|
||
let temp = assert_fs::TempDir::new().unwrap(); | ||
let sample_path = temp.child(sample.name()); | ||
sample_path.write_str(sample.content()).unwrap(); | ||
|
||
bencher | ||
.counter(divan::counter::BytesCount::of_str(sample.content())) | ||
.bench_local(|| { | ||
typos_cli::file::Typos.check_file(sample_path.path(), true, &policy, &PrintSilent) | ||
}) | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub struct PrintSilent; | ||
|
||
impl typos_cli::report::Report for PrintSilent { | ||
fn report(&self, _msg: typos_cli::report::Message) -> Result<(), std::io::Error> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
divan::main(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
mod regular { | ||
mod ok { | ||
#[divan::bench] | ||
fn en(bencher: divan::Bencher) { | ||
let input = "finalizes"; | ||
let locale = typos_cli::config::Locale::En; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
#[cfg(feature = "vars")] | ||
assert_eq!(corrections.correct_word(input), None); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
|
||
#[divan::bench] | ||
#[cfg(feature = "vars")] | ||
fn en_us(bencher: divan::Bencher) { | ||
let input = "finalizes"; | ||
let locale = typos_cli::config::Locale::EnUs; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
#[cfg(feature = "vars")] | ||
assert_eq!(corrections.correct_word(input), Some(typos::Status::Valid)); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
} | ||
|
||
mod misspell { | ||
#[divan::bench] | ||
fn en(bencher: divan::Bencher) { | ||
let input = "finallizes"; | ||
let output = "finalizes"; | ||
let locale = typos_cli::config::Locale::En; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
|
||
#[divan::bench] | ||
#[cfg(feature = "vars")] | ||
fn en_us(bencher: divan::Bencher) { | ||
let input = "finallizes"; | ||
let output = "finalizes"; | ||
let locale = typos_cli::config::Locale::EnUs; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
} | ||
|
||
mod misspell_case { | ||
#[divan::bench] | ||
fn en(bencher: divan::Bencher) { | ||
let input = "FINALLIZES"; | ||
let output = "FINALIZES"; | ||
let locale = typos_cli::config::Locale::En; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
|
||
#[divan::bench] | ||
#[cfg(feature = "vars")] | ||
fn en_us(bencher: divan::Bencher) { | ||
let input = "FINALLIZES"; | ||
let output = "FINALIZES"; | ||
let locale = typos_cli::config::Locale::EnUs; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "vars")] | ||
mod varcon { | ||
mod ok { | ||
#[divan::bench] | ||
fn en_gb(bencher: divan::Bencher) { | ||
let input = "finalizes"; | ||
let output = "finalises"; | ||
let locale = typos_cli::config::Locale::EnGb; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
} | ||
|
||
mod misspell { | ||
#[divan::bench] | ||
fn en_gb(bencher: divan::Bencher) { | ||
let input = "finallizes"; | ||
let output = "finalises"; | ||
let locale = typos_cli::config::Locale::EnGb; | ||
let corrections = typos_cli::dict::BuiltIn::new(locale); | ||
let input = typos::tokens::Word::new(input, 0).unwrap(); | ||
assert_eq!( | ||
corrections.correct_word(input), | ||
Some(typos::Status::Corrections(vec![ | ||
std::borrow::Cow::Borrowed(output) | ||
])) | ||
); | ||
bencher | ||
.with_inputs(|| input) | ||
.bench_local_values(|input| corrections.correct_word(input)); | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
divan::main(); | ||
} |
Oops, something went wrong.