summaryrefslogtreecommitdiffstats
path: root/vendor/unicode-segmentation/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/unicode-segmentation/benches
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/unicode-segmentation/benches')
-rw-r--r--vendor/unicode-segmentation/benches/graphemes.rs63
-rw-r--r--vendor/unicode-segmentation/benches/unicode_words.rs64
-rw-r--r--vendor/unicode-segmentation/benches/word_bounds.rs64
3 files changed, 191 insertions, 0 deletions
diff --git a/vendor/unicode-segmentation/benches/graphemes.rs b/vendor/unicode-segmentation/benches/graphemes.rs
new file mode 100644
index 000000000..3a0b9b76a
--- /dev/null
+++ b/vendor/unicode-segmentation/benches/graphemes.rs
@@ -0,0 +1,63 @@
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use unicode_segmentation;
+
+use std::fs;
+use unicode_segmentation::UnicodeSegmentation;
+
+fn graphemes(c: &mut Criterion, lang: &str, path: &str) {
+ let text = fs::read_to_string(path).unwrap();
+
+ c.bench_function(&format!("graphemes_{}", lang), |bench| {
+ bench.iter(|| {
+ for g in UnicodeSegmentation::graphemes(black_box(&*text), true) {
+ black_box(g);
+ }
+ })
+ });
+}
+
+fn graphemes_arabic(c: &mut Criterion) {
+ graphemes(c, "arabic", "benches/texts/arabic.txt");
+}
+
+fn graphemes_english(c: &mut Criterion) {
+ graphemes(c, "english", "benches/texts/english.txt");
+}
+
+fn graphemes_hindi(c: &mut Criterion) {
+ graphemes(c, "hindi", "benches/texts/hindi.txt");
+}
+
+fn graphemes_japanese(c: &mut Criterion) {
+ graphemes(c, "japanese", "benches/texts/japanese.txt");
+}
+
+fn graphemes_korean(c: &mut Criterion) {
+ graphemes(c, "korean", "benches/texts/korean.txt");
+}
+
+fn graphemes_mandarin(c: &mut Criterion) {
+ graphemes(c, "mandarin", "benches/texts/mandarin.txt");
+}
+
+fn graphemes_russian(c: &mut Criterion) {
+ graphemes(c, "russian", "benches/texts/russian.txt");
+}
+
+fn graphemes_source_code(c: &mut Criterion) {
+ graphemes(c, "source_code", "benches/texts/source_code.txt");
+}
+
+criterion_group!(
+ benches,
+ graphemes_arabic,
+ graphemes_english,
+ graphemes_hindi,
+ graphemes_japanese,
+ graphemes_korean,
+ graphemes_mandarin,
+ graphemes_russian,
+ graphemes_source_code,
+);
+
+criterion_main!(benches);
diff --git a/vendor/unicode-segmentation/benches/unicode_words.rs b/vendor/unicode-segmentation/benches/unicode_words.rs
new file mode 100644
index 000000000..c87851a37
--- /dev/null
+++ b/vendor/unicode-segmentation/benches/unicode_words.rs
@@ -0,0 +1,64 @@
+#[macro_use]
+extern crate bencher;
+extern crate unicode_segmentation;
+
+use bencher::Bencher;
+use std::fs;
+use unicode_segmentation::UnicodeSegmentation;
+
+fn unicode_words(bench: &mut Bencher, path: &str) {
+ let text = fs::read_to_string(path).unwrap();
+ bench.iter(|| {
+ for w in text.unicode_words() {
+ bencher::black_box(w);
+ }
+ });
+
+ bench.bytes = text.len() as u64;
+}
+
+fn unicode_words_arabic(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/arabic.txt");
+}
+
+fn unicode_words_english(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/english.txt");
+}
+
+fn unicode_words_hindi(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/hindi.txt");
+}
+
+fn unicode_words_japanese(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/japanese.txt");
+}
+
+fn unicode_words_korean(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/korean.txt");
+}
+
+fn unicode_words_mandarin(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/mandarin.txt");
+}
+
+fn unicode_words_russian(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/russian.txt");
+}
+
+fn unicode_words_source_code(bench: &mut Bencher) {
+ unicode_words(bench, "benches/texts/source_code.txt");
+}
+
+benchmark_group!(
+ benches,
+ unicode_words_arabic,
+ unicode_words_english,
+ unicode_words_hindi,
+ unicode_words_japanese,
+ unicode_words_korean,
+ unicode_words_mandarin,
+ unicode_words_russian,
+ unicode_words_source_code,
+);
+
+benchmark_main!(benches);
diff --git a/vendor/unicode-segmentation/benches/word_bounds.rs b/vendor/unicode-segmentation/benches/word_bounds.rs
new file mode 100644
index 000000000..6b01ddb10
--- /dev/null
+++ b/vendor/unicode-segmentation/benches/word_bounds.rs
@@ -0,0 +1,64 @@
+#[macro_use]
+extern crate bencher;
+extern crate unicode_segmentation;
+
+use bencher::Bencher;
+use std::fs;
+use unicode_segmentation::UnicodeSegmentation;
+
+fn word_bounds(bench: &mut Bencher, path: &str) {
+ let text = fs::read_to_string(path).unwrap();
+ bench.iter(|| {
+ for w in text.split_word_bounds() {
+ bencher::black_box(w);
+ }
+ });
+
+ bench.bytes = text.len() as u64;
+}
+
+fn word_bounds_arabic(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/arabic.txt");
+}
+
+fn word_bounds_english(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/english.txt");
+}
+
+fn word_bounds_hindi(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/hindi.txt");
+}
+
+fn word_bounds_japanese(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/japanese.txt");
+}
+
+fn word_bounds_korean(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/korean.txt");
+}
+
+fn word_bounds_mandarin(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/mandarin.txt");
+}
+
+fn word_bounds_russian(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/russian.txt");
+}
+
+fn word_bounds_source_code(bench: &mut Bencher) {
+ word_bounds(bench, "benches/texts/source_code.txt");
+}
+
+benchmark_group!(
+ benches,
+ word_bounds_arabic,
+ word_bounds_english,
+ word_bounds_hindi,
+ word_bounds_japanese,
+ word_bounds_korean,
+ word_bounds_mandarin,
+ word_bounds_russian,
+ word_bounds_source_code,
+);
+
+benchmark_main!(benches);