aboutsummaryrefslogtreecommitdiff
path: root/benches/unicode_words.rs
blob: c87851a3769814c7016c389ad8028d91f4341a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);