-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a97845
commit 7e90ed2
Showing
6 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
/result | ||
/.direnv/ | ||
/bench/target |
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 |
---|---|---|
@@ -1 +1 @@ | ||
editor.workspace-lsp-roots = ["examples"] | ||
editor.workspace-lsp-roots = ["examples", "bench"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,11 @@ | ||
[package] | ||
name = "benches" | ||
version = "0.1.0" | ||
edition = "2021" | ||
# Needed for `std::hint::black_box`. | ||
rust-version = "1.66" | ||
|
||
[dependencies] | ||
spellbook = { path = "../" } | ||
brunch = "0.5" | ||
xdg = "2.5" |
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,3 @@ | ||
Benchmarks for the spellbook API. Requires Rust 1.66 or higher. | ||
|
||
Run with `cargo run --release` in this `bench` directory. |
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,60 @@ | ||
use std::hint::black_box; | ||
|
||
use brunch::Bench; | ||
use spellbook::Dictionary; | ||
|
||
const SAMPLES: u32 = 500_000; | ||
|
||
fn main() { | ||
let base = xdg::BaseDirectories::new().expect("Could not determine XDG directories"); | ||
let (dic_path, aff_path) = match base.get_data_dirs().iter().find_map(|dir| { | ||
let subdir = dir.join("hunspell"); | ||
if !subdir.is_dir() { | ||
return None; | ||
} | ||
|
||
let dic = subdir.join("en_US.dic"); | ||
let aff = subdir.join("en_US.aff"); | ||
if dic.is_file() && aff.is_file() { | ||
Some((dic, aff)) | ||
} else { | ||
None | ||
} | ||
}) { | ||
Some((dic, aff)) => (dic, aff), | ||
None => { | ||
eprintln!("Could not find the en_US dictionary"); | ||
std::process::exit(1); | ||
} | ||
}; | ||
let dic_text = std::fs::read_to_string(dic_path).unwrap(); | ||
let aff_text = std::fs::read_to_string(aff_path).unwrap(); | ||
let dict = Dictionary::compile(&aff_text, &dic_text).unwrap(); | ||
|
||
eprintln!("Starting benchmarks..."); | ||
eprintln!(); | ||
let now = std::time::Instant::now(); | ||
brunch::benches!( | ||
inline: | ||
|
||
// Compilation | ||
Bench::new("Compile en_US") | ||
.run(|| Dictionary::compile(black_box(&aff_text), black_box(&dic_text))), | ||
Bench::spacer(), | ||
|
||
// Checking | ||
Bench::new("In-dictionary word (\"drink\")") | ||
.with_samples(SAMPLES) | ||
.run(|| dict.check(black_box("drink"))), | ||
Bench::new("Word with a suffix (\"drinkable\")") | ||
.with_samples(SAMPLES) | ||
.run(|| dict.check(black_box("drinkable"))), | ||
Bench::new("Multi-affix (\"undrinkable\")") | ||
.with_samples(SAMPLES) | ||
.run(|| dict.check(black_box("undrinkable"))), | ||
Bench::new("Incorrect prefix (\"undrink\")") | ||
.with_samples(SAMPLES) | ||
.run(|| dict.check(black_box("undrink"))), | ||
); | ||
eprintln!("Finished in {:.1}s", now.elapsed().as_secs_f64()); | ||
} |