-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2 separate literal string implementations - lazy and precomputed to avoid string clone no longer limited to ascii added examples bench sprinkled must_use
- Loading branch information
Showing
14 changed files
with
396 additions
and
178 deletions.
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
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,55 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use sayit::Accent; | ||
use std::{fs, path::PathBuf}; | ||
|
||
pub fn read_accent(filename: &PathBuf) -> Accent { | ||
let content = fs::read_to_string(filename).expect("reading accent definition"); | ||
ron::from_str::<Accent>(&content) | ||
.unwrap_or_else(|_| panic!("parsing accent {}", filename.display())) | ||
} | ||
|
||
pub fn read_sample_file() -> String { | ||
fs::read_to_string("tests/sample_text.txt").expect("reading sample text") | ||
} | ||
|
||
pub fn read_sample_file_lines() -> Vec<String> { | ||
read_sample_file() | ||
.lines() | ||
.filter(|&l| !(l.is_empty() || l.eq(" :"))) | ||
.map(|s| s.to_owned()) | ||
.collect() | ||
} | ||
|
||
fn examples(c: &mut Criterion) { | ||
let lines = read_sample_file_lines(); | ||
|
||
let mut g = c.benchmark_group("examples"); | ||
g.sampling_mode(criterion::SamplingMode::Linear); | ||
|
||
for entry in fs::read_dir("examples").unwrap() { | ||
let path = entry.unwrap().path(); | ||
|
||
if !path.is_file() { | ||
continue; | ||
} | ||
|
||
if !path.extension().is_some_and(|ext| ext == "ron") { | ||
continue; | ||
} | ||
|
||
let accent = read_accent(&path); | ||
let accent_name = path.file_stem().unwrap().to_string_lossy(); | ||
|
||
g.bench_function(accent_name, |b| { | ||
b.iter(|| { | ||
for line in &lines { | ||
let _ = accent.say_it(line, 0); | ||
} | ||
}) | ||
}); | ||
} | ||
g.finish(); | ||
} | ||
|
||
criterion_group!(benches, examples); | ||
criterion_main!(benches); |
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
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
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
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
Oops, something went wrong.