File: word_bounds.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (61 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (5)
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
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use std::fs;
use unicode_segmentation::UnicodeSegmentation;

fn word_bounds(c: &mut Criterion, lang: &str, path: &str) {
    let text = fs::read_to_string(path).unwrap();
    c.bench_function(&format!("word_bounds_{}", lang), |bench| {
        bench.iter(|| {
            for w in text.split_word_bounds() {
                black_box(w);
            }
        });
    });
}

fn word_bounds_arabic(c: &mut Criterion) {
    word_bounds(c, "arabic", "benches/texts/arabic.txt");
}

fn word_bounds_english(c: &mut Criterion) {
    word_bounds(c, "english", "benches/texts/english.txt");
}

fn word_bounds_hindi(c: &mut Criterion) {
    word_bounds(c, "hindi", "benches/texts/hindi.txt");
}

fn word_bounds_japanese(c: &mut Criterion) {
    word_bounds(c, "japanese", "benches/texts/japanese.txt");
}

fn word_bounds_korean(c: &mut Criterion) {
    word_bounds(c, "korean", "benches/texts/korean.txt");
}

fn word_bounds_mandarin(c: &mut Criterion) {
    word_bounds(c, "mandarin", "benches/texts/mandarin.txt");
}

fn word_bounds_russian(c: &mut Criterion) {
    word_bounds(c, "russian", "benches/texts/russian.txt");
}

fn word_bounds_source_code(c: &mut Criterion) {
    word_bounds(c, "source_code", "benches/texts/source_code.txt");
}

criterion_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,
);

criterion_main!(benches);