summaryrefslogtreecommitdiffstats
path: root/third_party/rust/unicode-segmentation/benches/graphemes.rs
blob: 3a0b9b76a315512975c6746e29503c3929e59750 (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
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);