1 #[macro_use]
2 extern crate bencher;
3 extern crate unicode_segmentation;
4 
5 use bencher::Bencher;
6 use unicode_segmentation::UnicodeSegmentation;
7 use std::fs;
8 
9 fn unicode_words(bench: &mut Bencher, path: &str) {
10     let text = fs::read_to_string(path).unwrap();
11     bench.iter(|| {
12         for w in text.unicode_words() {
13             bencher::black_box(w);
14         }
15     });
16 
17     bench.bytes = text.len() as u64;
18 }
19 
20 fn unicode_words_arabic(bench: &mut Bencher) {
21     unicode_words(bench, "benches/texts/arabic.txt");
22 }
23 
24 fn unicode_words_english(bench: &mut Bencher) {
25     unicode_words(bench, "benches/texts/english.txt");
26 }
27 
28 fn unicode_words_hindi(bench: &mut Bencher) {
29     unicode_words(bench, "benches/texts/hindi.txt");
30 }
31 
32 fn unicode_words_japanese(bench: &mut Bencher) {
33     unicode_words(bench, "benches/texts/japanese.txt");
34 }
35 
36 fn unicode_words_korean(bench: &mut Bencher) {
37     unicode_words(bench, "benches/texts/korean.txt");
38 }
39 
40 fn unicode_words_mandarin(bench: &mut Bencher) {
41     unicode_words(bench, "benches/texts/mandarin.txt");
42 }
43 
44 fn unicode_words_russian(bench: &mut Bencher) {
45     unicode_words(bench, "benches/texts/russian.txt");
46 }
47 
48 fn unicode_words_source_code(bench: &mut Bencher) {
49     unicode_words(bench, "benches/texts/source_code.txt");
50 }
51 
52 benchmark_group!(
53     benches,
54     unicode_words_arabic,
55     unicode_words_english,
56     unicode_words_hindi,
57     unicode_words_japanese,
58     unicode_words_korean,
59     unicode_words_mandarin,
60     unicode_words_russian,
61     unicode_words_source_code,
62 );
63 
64 benchmark_main!(benches);
65