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;
43
5- use bencher:: Bencher ;
6- use unicode_segmentation:: UnicodeSegmentation ;
74use std:: fs;
5+ use unicode_segmentation:: UnicodeSegmentation ;
86
9- fn graphemes ( bench : & mut Bencher , path : & str ) {
7+ fn graphemes ( c : & mut Criterion , lang : & str , path : & str ) {
108let text = fs:: read_to_string ( path) . unwrap ( ) ;
11- bench. iter ( ||{
12- for gin UnicodeSegmentation :: graphemes ( & * text, true ) {
13- bencher:: black_box ( g) ;
14- }
15- } ) ;
169
17- bench. bytes = text. len ( ) as u64 ;
10+ c. bench_function ( & format ! ( "graphemes_{}" , lang) , |bench|{
11+ bench. iter ( ||{
12+ for gin UnicodeSegmentation :: graphemes ( black_box ( & * text) , true ) {
13+ black_box ( g) ;
14+ }
15+ } )
16+ } ) ;
1817}
1918
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" ) ;
2221}
2322
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" ) ;
2625}
2726
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" ) ;
3029}
3130
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" ) ;
3433}
3534
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" ) ;
3837}
3938
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" ) ;
4241}
4342
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" ) ;
4645}
4746
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" ) ;
5049}
5150
52- benchmark_group ! (
51+ criterion_group ! (
5352 benches,
5453 graphemes_arabic,
5554 graphemes_english,
@@ -61,4 +60,4 @@ benchmark_group!(
6160 graphemes_source_code,
6261) ;
6362
64- benchmark_main ! ( benches) ;
63+ criterion_main ! ( benches) ;