Skip to content

Commit

Permalink
Merge pull request #194 from epage/arch2
Browse files Browse the repository at this point in the history
fix(fix): Update as we go
  • Loading branch information
epage authored Jan 3, 2021
2 parents f103296 + 67222e9 commit 1c392c2
Show file tree
Hide file tree
Showing 17 changed files with 1,137 additions and 1,183 deletions.
144 changes: 69 additions & 75 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ ahash = "0.6.1"
difflib = "0.4"
proc-exit = "1.0"
human-panic = "1.0.3"
content_inspector = "0.2.4"
unicode-segmentation = "1.6.0"
derive_more = "0.99.11"
derive_setters = "0.1"
itertools = "0.9"
serde_json = "1.0"

[dev-dependencies]
assert_fs = "1.0"
Expand Down
202 changes: 100 additions & 102 deletions benches/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,210 +5,208 @@ extern crate test;
mod data;

use assert_fs::prelude::*;
use typos::checks::Check;
use typos_cli::checks::FileChecker;

fn bench_files(data: &str, b: &mut test::Bencher) {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(data).unwrap();

fn bench_parse_ident_str(data: &str, b: &mut test::Bencher) {
let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Parser::new();
let checks = typos::checks::TyposSettings::new().build_identifier_parser();
b.iter(|| checks.check_str(data, &parser, &corrections, &typos::report::PrintSilent));
let parser = typos::tokens::Tokenizer::new();
let checks = typos_cli::checks::TyposSettings::new().build_files();
b.iter(|| {
checks.check_file(
sample_path.path(),
true,
&parser,
&corrections,
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
}

#[bench]
fn parse_idents_empty_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::EMPTY, b);
fn files_empty(b: &mut test::Bencher) {
bench_files(data::EMPTY, b);
}

#[bench]
fn parse_idents_no_tokens_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::NO_TOKENS, b);
fn files_no_tokens(b: &mut test::Bencher) {
bench_files(data::NO_TOKENS, b);
}

#[bench]
fn parse_idents_single_token_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::SINGLE_TOKEN, b);
fn files_single_token(b: &mut test::Bencher) {
bench_files(data::SINGLE_TOKEN, b);
}

#[bench]
fn parse_idents_sherlock_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::SHERLOCK, b);
fn files_sherlock(b: &mut test::Bencher) {
bench_files(data::SHERLOCK, b);
}

#[bench]
fn parse_idents_code_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::CODE, b);
fn files_code(b: &mut test::Bencher) {
bench_files(data::CODE, b);
}

#[bench]
fn parse_idents_corpus_str(b: &mut test::Bencher) {
bench_parse_ident_str(data::CORPUS, b);
fn files_corpus(b: &mut test::Bencher) {
bench_files(data::CORPUS, b);
}

fn bench_parse_ident_bytes(data: &str, b: &mut test::Bencher) {
fn bench_identifiers(data: &str, b: &mut test::Bencher) {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(data).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Parser::new();
let checks = typos::checks::TyposSettings::new().build_identifier_parser();
let parser = typos::tokens::Tokenizer::new();
let checks = typos_cli::checks::TyposSettings::new().build_identifier_parser();
b.iter(|| {
checks.check_bytes(
data.as_bytes(),
checks.check_file(
sample_path.path(),
true,
&parser,
&corrections,
&typos::report::PrintSilent,
&typos_cli::report::PrintSilent,
)
});
}

#[bench]
fn parse_idents_empty_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::EMPTY, b);
}

#[bench]
fn parse_idents_no_tokens_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::NO_TOKENS, b);
}

#[bench]
fn parse_idents_single_token_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::SINGLE_TOKEN, b);
}

#[bench]
fn parse_idents_sherlock_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::SHERLOCK, b);
}

#[bench]
fn parse_idents_code_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::CODE, b);
temp.close().unwrap();
}

#[bench]
fn parse_idents_corpus_bytes(b: &mut test::Bencher) {
bench_parse_ident_bytes(data::CORPUS, b);
}

fn bench_parse_word_str(data: &str, b: &mut test::Bencher) {
let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Parser::new();
let checks = typos::checks::TyposSettings::new().build_word_parser();
b.iter(|| checks.check_str(data, &parser, &corrections, &typos::report::PrintSilent));
fn identifiers_empty(b: &mut test::Bencher) {
bench_identifiers(data::EMPTY, b);
}

#[bench]
fn parse_words_empty(b: &mut test::Bencher) {
bench_parse_word_str(data::EMPTY, b);
fn identifiers_no_tokens(b: &mut test::Bencher) {
bench_identifiers(data::NO_TOKENS, b);
}

#[bench]
fn parse_words_no_tokens(b: &mut test::Bencher) {
bench_parse_word_str(data::NO_TOKENS, b);
fn identifiers_single_token(b: &mut test::Bencher) {
bench_identifiers(data::SINGLE_TOKEN, b);
}

#[bench]
fn parse_words_single_token(b: &mut test::Bencher) {
bench_parse_word_str(data::SINGLE_TOKEN, b);
fn identifiers_sherlock(b: &mut test::Bencher) {
bench_identifiers(data::SHERLOCK, b);
}

#[bench]
fn parse_words_sherlock(b: &mut test::Bencher) {
bench_parse_word_str(data::SHERLOCK, b);
fn identifiers_code(b: &mut test::Bencher) {
bench_identifiers(data::CODE, b);
}

#[bench]
fn parse_words_code(b: &mut test::Bencher) {
bench_parse_word_str(data::CODE, b);
fn identifiers_corpus(b: &mut test::Bencher) {
bench_identifiers(data::CORPUS, b);
}

#[bench]
fn parse_words_corpus(b: &mut test::Bencher) {
bench_parse_word_str(data::CORPUS, b);
}
fn bench_words(data: &str, b: &mut test::Bencher) {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(data).unwrap();

fn bench_typos(data: &str, b: &mut test::Bencher) {
let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Parser::new();
let checks = typos::checks::TyposSettings::new().build_typos();
b.iter(|| checks.check_str(data, &parser, &corrections, &typos::report::PrintSilent));
let parser = typos::tokens::Tokenizer::new();
let checks = typos_cli::checks::TyposSettings::new().build_word_parser();
b.iter(|| {
checks.check_file(
sample_path.path(),
true,
&parser,
&corrections,
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
}

#[bench]
fn typos_empty(b: &mut test::Bencher) {
bench_typos(data::EMPTY, b);
fn words_empty(b: &mut test::Bencher) {
bench_words(data::EMPTY, b);
}

#[bench]
fn typos_no_tokens(b: &mut test::Bencher) {
bench_typos(data::NO_TOKENS, b);
fn words_no_tokens(b: &mut test::Bencher) {
bench_words(data::NO_TOKENS, b);
}

#[bench]
fn typos_single_token(b: &mut test::Bencher) {
bench_typos(data::SINGLE_TOKEN, b);
fn words_single_token(b: &mut test::Bencher) {
bench_words(data::SINGLE_TOKEN, b);
}

#[bench]
fn typos_sherlock(b: &mut test::Bencher) {
bench_typos(data::SHERLOCK, b);
fn words_sherlock(b: &mut test::Bencher) {
bench_words(data::SHERLOCK, b);
}

#[bench]
fn typos_code(b: &mut test::Bencher) {
bench_typos(data::CODE, b);
fn words_code(b: &mut test::Bencher) {
bench_words(data::CODE, b);
}

#[bench]
fn typos_corpus(b: &mut test::Bencher) {
bench_typos(data::CORPUS, b);
fn words_corpus(b: &mut test::Bencher) {
bench_words(data::CORPUS, b);
}

fn bench_check_file(data: &str, b: &mut test::Bencher) {
fn bench_typos(data: &str, b: &mut test::Bencher) {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(data).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Parser::new();
let checks = typos::checks::TyposSettings::new().build_typos();
let parser = typos::tokens::Tokenizer::new();
let checks = typos_cli::checks::TyposSettings::new().build_typos();
b.iter(|| {
checks.check_file(
sample_path.path(),
true,
&parser,
&corrections,
&typos::report::PrintSilent,
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
}

#[bench]
fn check_file_empty(b: &mut test::Bencher) {
bench_check_file(data::EMPTY, b);
fn typos_empty(b: &mut test::Bencher) {
bench_typos(data::EMPTY, b);
}

#[bench]
fn check_file_no_tokens(b: &mut test::Bencher) {
bench_check_file(data::NO_TOKENS, b);
fn typos_no_tokens(b: &mut test::Bencher) {
bench_typos(data::NO_TOKENS, b);
}

#[bench]
fn check_file_single_token(b: &mut test::Bencher) {
bench_check_file(data::SINGLE_TOKEN, b);
fn typos_single_token(b: &mut test::Bencher) {
bench_typos(data::SINGLE_TOKEN, b);
}

#[bench]
fn check_file_sherlock(b: &mut test::Bencher) {
bench_check_file(data::SHERLOCK, b);
fn typos_sherlock(b: &mut test::Bencher) {
bench_typos(data::SHERLOCK, b);
}

#[bench]
fn check_file_code(b: &mut test::Bencher) {
bench_check_file(data::CODE, b);
fn typos_code(b: &mut test::Bencher) {
bench_typos(data::CODE, b);
}

#[bench]
fn check_file_corpus(b: &mut test::Bencher) {
bench_check_file(data::CORPUS, b);
fn typos_corpus(b: &mut test::Bencher) {
bench_typos(data::CORPUS, b);
}
12 changes: 6 additions & 6 deletions benches/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ mod data;

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

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

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

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

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

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

Expand Down
5 changes: 0 additions & 5 deletions crates/typos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ thiserror = "1.0"
regex = "1.3"
once_cell = "1.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
itertools = "0.9"
bstr = "0.2"
log = "0.4"
unicode-segmentation = "1.7.1"
derive_more = "0.99.11"
derive_setters = "0.1"
content_inspector = "0.2.4"
Loading

0 comments on commit 1c392c2

Please sign in to comment.