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