1- #[ macro_use]
2- extern crate bencher;
3- extern crate unicode_segmentation;
1+ use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
42
5- use bencher:: Bencher ;
63use std:: fs;
74use unicode_segmentation:: UnicodeSegmentation ;
85
9- fn unicode_words ( bench : & mut Bencher , path : & str ) {
6+ fn unicode_words ( c : & mut Criterion , lang : & str , path : & str ) {
107let text = fs:: read_to_string ( path) . unwrap ( ) ;
11- bench. iter ( ||{
12- for win text. unicode_words ( ) {
13- bencher:: black_box ( w) ;
14- }
8+ c. bench_function ( & format ! ( "unicode_words_{}" , lang) , |bench|{
9+ bench. iter ( ||{
10+ for win text. unicode_words ( ) {
11+ black_box ( w) ;
12+ }
13+ } )
1514} ) ;
16-
17- bench. bytes = text. len ( ) as u64 ;
1815}
1916
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" ) ;
2219}
2320
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" ) ;
2623}
2724
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" ) ;
3027}
3128
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" ) ;
3431}
3532
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" ) ;
3835}
3936
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" ) ;
4239}
4340
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" ) ;
4643}
4744
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" ) ;
5047}
5148
52- benchmark_group ! (
49+ criterion_group ! (
5350 benches,
5451 unicode_words_arabic,
5552 unicode_words_english,
@@ -61,4 +58,4 @@ benchmark_group!(
6158 unicode_words_source_code,
6259) ;
6360
64- benchmark_main ! ( benches) ;
61+ criterion_main ! ( benches) ;