Skip to content
Draft
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
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/typos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ encoding_rs = "0.8.32"
assert_fs = "1.0"
trycmd = "0.14.16"
criterion = "0.5"
calliper = { git = "https://github.com/osiewicz/calliper.git" }

[[bench]]
name = "checks"
Expand All @@ -98,3 +99,7 @@ harness = false
[[bench]]
name = "tokenize"
harness = false

[[bench]]
name = "cli"
harness = false
29 changes: 29 additions & 0 deletions crates/typos-cli/benches/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use calliper::{Runner, Scenario, ScenarioConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let runner = Runner::default().config(ScenarioConfig::default().branch_sim(true));
let benches = [
Scenario::new_with_command(cmd(&["benches/data/empty.txt"])).name("empty.txt"),
Scenario::new_with_command(cmd(&["benches/data/no_tokens.txt"])).name("no_tokens.txt"),
Scenario::new_with_command(cmd(&["benches/data/single_token.txt"]))
.name("single_token.txt"),
Scenario::new_with_command(cmd(&["benches/data/sherlock.txt"])).name("sherlock.txt"),
Scenario::new_with_command(cmd(&["benches/data/code.txt"])).name("code.txt"),
Scenario::new_with_command(cmd(&["../typos-dict/assets/words.csv"])).name("words.csv"),
];
if let Some(results) = runner.run(&benches)? {
for res in results.into_iter() {
println!("{}", res.parse());
}
}
Ok(())
}

fn cmd(args: &[&str]) -> std::process::Command {
let bin = std::path::Path::new(env!("CARGO_BIN_EXE_typos"));

let mut cmd = std::process::Command::new(bin);
cmd.args(args);

cmd
}
28 changes: 5 additions & 23 deletions crates/typos-cli/benches/data.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
pub static EMPTY: &str = "";
pub static EMPTY: &str = include_str!("data/empty.txt");

pub static NO_TOKENS: &str = " ";
pub static NO_TOKENS: &str = include_str!("data/no_tokens.txt");

pub static SINGLE_TOKEN: &str = "success";
pub static SINGLE_TOKEN: &str = include_str!("data/single_token.txt");

// Stolen from https://github.com/BurntSushi/ripgrep/blob/master/grep-searcher/src/searcher/glue.rs
pub static SHERLOCK: &str = "\
For the Doctor Watsons of this world, as opposed to the Sherlock
Holmeses, success in the province of detective work must always
be, to a very large extent, the result of luck. Sherlock Holmes
can extract a clew from a wisp of straw or a flake of cigar ash;
but Doctor Watson has to have it taken out for him and dusted,
and exhibited clearly, with a label attached.\
";
pub static SHERLOCK: &str = include_str!("data/sherlock.txt");

// Stolen from https://github.com/BurntSushi/ripgrep/blob/master/grep-searcher/src/searcher/glue.rs
pub static CODE: &str = "\
extern crate snap;
use std::io;
fn main() {
let stdin = io::stdin();
let stdout = io::stdout();
// Wrap the stdin reader in a Snappy reader.
let mut rdr = snap::Reader::new(stdin.lock());
let mut wtr = stdout.lock();
io::copy(&mut rdr, &mut wtr).expect(\"I/O operation failed\");
}
";
pub static CODE: &str = include_str!("data/code.txt");

pub static CORPUS: &str = include_str!("../../typos-dict/assets/words.csv");

Expand Down
10 changes: 10 additions & 0 deletions crates/typos-cli/benches/data/code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern crate snap;
use std::io;
fn main() {
let stdin = io::stdin();
let stdout = io::stdout();
// Wrap the stdin reader in a Snappy reader.
let mut rdr = snap::Reader::new(stdin.lock());
let mut wtr = stdout.lock();
io::copy(&mut rdr, &mut wtr).expect(\"I/O operation failed\");
}
Empty file.
1 change: 1 addition & 0 deletions crates/typos-cli/benches/data/no_tokens.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions crates/typos-cli/benches/data/sherlock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
For the Doctor Watsons of this world, as opposed to the Sherlock
Holmeses, success in the province of detective work must always
be, to a very large extent, the result of luck. Sherlock Holmes
can extract a clew from a wisp of straw or a flake of cigar ash;
but Doctor Watson has to have it taken out for him and dusted,
and exhibited clearly, with a label attached.\
1 change: 1 addition & 0 deletions crates/typos-cli/benches/data/single_token.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success