Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to make the code more approachable #47

Merged
merged 8 commits into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benches/corrections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ extern crate test;

#[bench]
fn load_corrections(b: &mut test::Bencher) {
b.iter(|| typos::Dictionary::new());
b.iter(|| typos::BuiltIn::new());
}

#[bench]
fn correct_word_hit(b: &mut test::Bencher) {
let corrections = typos::Dictionary::new();
let corrections = typos::BuiltIn::new();
let input = typos::tokens::Word::new("successs", 0).unwrap();
assert_eq!(
corrections.correct_word(input),
Expand All @@ -20,7 +20,7 @@ fn correct_word_hit(b: &mut test::Bencher) {

#[bench]
fn correct_word_miss(b: &mut test::Bencher) {
let corrections = typos::Dictionary::new();
let corrections = typos::BuiltIn::new();
let input = typos::tokens::Word::new("success", 0).unwrap();
assert_eq!(corrections.correct_word(input), None);
b.iter(|| corrections.correct_word(input));
Expand Down
96 changes: 24 additions & 72 deletions benches/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ fn process_empty(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::EMPTY).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
Expand All @@ -34,18 +26,10 @@ fn process_no_tokens(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::NO_TOKENS).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
Expand All @@ -56,18 +40,10 @@ fn process_single_token(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::SINGLE_TOKEN).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
Expand All @@ -78,18 +54,10 @@ fn process_sherlock(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::SHERLOCK).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
Expand All @@ -100,18 +68,10 @@ fn process_code(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::CODE).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
Expand All @@ -122,18 +82,10 @@ fn process_corpus(b: &mut test::Bencher) {
let sample_path = temp.child("sample");
sample_path.write_str(data::CORPUS).unwrap();

let corrections = typos::Dictionary::new();
b.iter(|| {
typos::process_file(
sample_path.path(),
&corrections,
true,
true,
true,
false,
typos::report::print_silent,
)
});
let corrections = typos::BuiltIn::new();
let parser = typos::tokens::Parser::new();
let checks = typos::checks::CheckSettings::new().build(&corrections, &parser);
b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent));

temp.close().unwrap();
}
26 changes: 16 additions & 10 deletions benches/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,66 @@ mod data;

#[bench]
fn symbol_parse_empty(b: &mut test::Bencher) {
b.iter(|| typos::tokens::Identifier::parse_bytes(data::EMPTY.as_bytes()).last());
let parser = typos::tokens::Parser::new();
b.iter(|| parser.parse_bytes(data::EMPTY.as_bytes()).last());
}

#[bench]
fn symbol_parse_no_tokens(b: &mut test::Bencher) {
b.iter(|| typos::tokens::Identifier::parse_bytes(data::NO_TOKENS.as_bytes()).last());
let parser = typos::tokens::Parser::new();
b.iter(|| parser.parse_bytes(data::NO_TOKENS.as_bytes()).last());
}

#[bench]
fn symbol_parse_single_token(b: &mut test::Bencher) {
let parser = typos::tokens::Parser::new();
b.iter(|| {
typos::tokens::Identifier::parse_bytes(data::SINGLE_TOKEN.as_bytes()).last();
parser.parse_bytes(data::SINGLE_TOKEN.as_bytes()).last();
});
}

#[bench]
fn symbol_parse_sherlock(b: &mut test::Bencher) {
b.iter(|| typos::tokens::Identifier::parse_bytes(data::SHERLOCK.as_bytes()).last());
let parser = typos::tokens::Parser::new();
b.iter(|| parser.parse_bytes(data::SHERLOCK.as_bytes()).last());
}

#[bench]
fn symbol_parse_code(b: &mut test::Bencher) {
b.iter(|| typos::tokens::Identifier::parse_bytes(data::CODE.as_bytes()).last());
let parser = typos::tokens::Parser::new();
b.iter(|| parser.parse_bytes(data::CODE.as_bytes()).last());
}

#[bench]
fn symbol_parse_corpus(b: &mut test::Bencher) {
b.iter(|| typos::tokens::Identifier::parse_bytes(data::CORPUS.as_bytes()).last());
let parser = typos::tokens::Parser::new();
b.iter(|| parser.parse_bytes(data::CORPUS.as_bytes()).last());
}

#[bench]
fn symbol_split_lowercase_short(b: &mut test::Bencher) {
let input = "abcabcabcabc";
let symbol = typos::tokens::Identifier::new(input, 0).unwrap();
let symbol = typos::tokens::Identifier::new_unchecked(input, 0);
b.iter(|| symbol.split().last());
}

#[bench]
fn symbol_split_lowercase_long(b: &mut test::Bencher) {
let input = "abcabcabcabc".repeat(90);
let symbol = typos::tokens::Identifier::new(&input, 0).unwrap();
let symbol = typos::tokens::Identifier::new_unchecked(&input, 0);
b.iter(|| symbol.split().last());
}

#[bench]
fn symbol_split_mixed_short(b: &mut test::Bencher) {
let input = "abcABCAbc123";
let symbol = typos::tokens::Identifier::new(input, 0).unwrap();
let symbol = typos::tokens::Identifier::new_unchecked(input, 0);
b.iter(|| symbol.split().last());
}

#[bench]
fn symbol_split_mixed_long(b: &mut test::Bencher) {
let input = "abcABCAbc123".repeat(90);
let symbol = typos::tokens::Identifier::new(&input, 0).unwrap();
let symbol = typos::tokens::Identifier::new_unchecked(&input, 0);
b.iter(|| symbol.split().last());
}
Loading