-
Notifications
You must be signed in to change notification settings - Fork 67
Add grapheme iteration benchmarks for various languages. #78
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #[macro_use] | ||
| extern crate bencher; | ||
| extern crate unicode_segmentation; | ||
|
|
||
| use bencher::Bencher; | ||
| use unicode_segmentation::UnicodeSegmentation; | ||
|
|
||
| const TEXT_ARABIC: &str = include_str!("texts/arabic.txt"); | ||
| const TEXT_ENGLISH: &str = include_str!("texts/english.txt"); | ||
| const TEXT_HINDI: &str = include_str!("texts/hindi.txt"); | ||
| const TEXT_JAPANESE: &str = include_str!("texts/japanese.txt"); | ||
| const TEXT_KOREAN: &str = include_str!("texts/korean.txt"); | ||
| const TEXT_MANDARIN: &str = include_str!("texts/mandarin.txt"); | ||
| const TEXT_RUSSIAN: &str = include_str!("texts/russian.txt"); | ||
| const TEXT_SOURCE_CODE: &str = include_str!("texts/source_code.txt"); | ||
|
|
||
| fn graphemes_arabic(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_ARABIC, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_ARABIC.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_english(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_ENGLISH, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_ENGLISH.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_hindi(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_HINDI, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_HINDI.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_japanese(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_JAPANESE, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_JAPANESE.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_korean(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_KOREAN, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_KOREAN.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_mandarin(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_MANDARIN, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_MANDARIN.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_russian(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_RUSSIAN, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_RUSSIAN.len() as u64; | ||
| } | ||
|
|
||
| fn graphemes_source_code(bench: &mut Bencher) { | ||
| bench.iter(|| { | ||
| for g in UnicodeSegmentation::graphemes(TEXT_SOURCE_CODE, true) { | ||
| bencher::black_box(g); | ||
| } | ||
| }); | ||
|
|
||
| bench.bytes = TEXT_SOURCE_CODE.len() as u64; | ||
| } | ||
|
|
||
| benchmark_group!( | ||
| benches, | ||
| graphemes_arabic, | ||
| graphemes_english, | ||
| graphemes_hindi, | ||
| graphemes_japanese, | ||
| graphemes_korean, | ||
| graphemes_mandarin, | ||
| graphemes_russian, | ||
| graphemes_source_code, | ||
| ); | ||
|
|
||
| benchmark_main!(benches); | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the text itself should also pass through
black_box. Probably doesn't matter given how large it is, but worth a shot.Alternatively, we can load the file dynamically outside of the
iter()call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a fix that does this.