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