summaryrefslogtreecommitdiffstats
path: root/third_party/rust/unicode-segmentation/benches/unicode_words.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/unicode-segmentation/benches/unicode_words.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/unicode-segmentation/benches/unicode_words.rs')
-rw-r--r--third_party/rust/unicode-segmentation/benches/unicode_words.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/third_party/rust/unicode-segmentation/benches/unicode_words.rs b/third_party/rust/unicode-segmentation/benches/unicode_words.rs
new file mode 100644
index 0000000000..c87851a376
--- /dev/null
+++ b/third_party/rust/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);