@@ -9,140 +9,209 @@ use criterion::{
9
9
} ;
10
10
11
11
const BUILD_SAMPLE_SIZE : usize = 10 ;
12
- const BUILD_WARM_UP_TIME : Duration = Duration :: from_secs ( 5 ) ;
13
- const BUILD_MEASURE_TIME : Duration = Duration :: from_secs ( 30 ) ;
12
+ const BUILD_WARM_UP_TIME : Duration = Duration :: from_millis ( 500 ) ;
13
+ const BUILD_MEASURE_TIME : Duration = Duration :: from_secs ( 2 ) ;
14
14
15
15
const SEARCH_SAMPLE_SIZE : usize = 30 ;
16
- const SEARCH_WARM_UP_TIME : Duration = Duration :: from_secs ( 5 ) ;
17
- const SEARCH_MEASURE_TIME : Duration = Duration :: from_secs ( 10 ) ;
18
-
19
- fn criterion_unidic_build ( c : & mut Criterion ) {
20
- let mut group = c. benchmark_group ( "unidic/build" ) ;
21
- group. sample_size ( BUILD_SAMPLE_SIZE ) ;
22
- group. warm_up_time ( BUILD_WARM_UP_TIME ) ;
23
- group. measurement_time ( BUILD_MEASURE_TIME ) ;
24
- group. sampling_mode ( SamplingMode :: Flat ) ;
25
- let mut patterns = load_file ( "data/unidic/unidic" ) ;
26
- patterns. sort_unstable ( ) ;
27
-
28
- add_build_benches ( & mut group, & patterns) ;
16
+ const SEARCH_WARM_UP_TIME : Duration = Duration :: from_millis ( 500 ) ;
17
+ const SEARCH_MEASURE_TIME : Duration = Duration :: from_secs ( 2 ) ;
18
+
19
+ macro_rules! define_build_bench {
20
+ ( $func_name: ident, $group: literal, $corpus: literal ) => {
21
+ fn $func_name( c: & mut Criterion ) {
22
+ let mut group = c. benchmark_group( $group) ;
23
+ group. sample_size( BUILD_SAMPLE_SIZE ) ;
24
+ group. warm_up_time( BUILD_WARM_UP_TIME ) ;
25
+ group. measurement_time( BUILD_MEASURE_TIME ) ;
26
+ group. sampling_mode( SamplingMode :: Flat ) ;
27
+ let mut patterns = load_file( $corpus) ;
28
+ patterns. sort_unstable( ) ;
29
+ add_build_benches( & mut group, & patterns) ;
30
+ }
31
+ } ;
29
32
}
30
33
31
- fn criterion_words100000_build ( c : & mut Criterion ) {
32
- let mut group = c. benchmark_group ( "words_100000/build" ) ;
33
- group. sample_size ( BUILD_SAMPLE_SIZE ) ;
34
- group. warm_up_time ( BUILD_WARM_UP_TIME ) ;
35
- group. measurement_time ( BUILD_MEASURE_TIME ) ;
36
- group. sampling_mode ( SamplingMode :: Flat ) ;
37
- let mut patterns = load_file ( "data/words_100000" ) ;
38
- patterns. sort_unstable ( ) ;
39
-
40
- add_build_benches ( & mut group, & patterns) ;
41
- }
42
-
43
- fn criterion_unidic_find ( c : & mut Criterion ) {
44
- let mut group = c. benchmark_group ( "unidic/find" ) ;
45
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
46
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
47
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
48
- group. sampling_mode ( SamplingMode :: Flat ) ;
49
- let mut patterns = load_file ( "data/unidic/unidic" ) ;
50
- patterns. sort_unstable ( ) ;
51
- let haystacks = load_file ( "data/wagahaiwa_nekodearu.txt" ) ;
52
-
53
- add_find_benches ( & mut group, & patterns, & haystacks) ;
54
- }
55
-
56
- fn criterion_words100000_find ( c : & mut Criterion ) {
57
- let mut group = c. benchmark_group ( "words_100000/find" ) ;
58
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
59
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
60
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
61
- group. sampling_mode ( SamplingMode :: Flat ) ;
62
- let mut patterns = load_file ( "data/words_100000" ) ;
63
- patterns. sort_unstable ( ) ;
64
- let haystacks = load_file ( "data/sherlock.txt" ) ;
65
-
66
- add_find_benches ( & mut group, & patterns, & haystacks) ;
34
+ macro_rules! define_find_bench {
35
+ ( $func_name: ident, $bench: ident, $group: literal, $corpus: literal, $haystack: literal ) => {
36
+ fn $func_name( c: & mut Criterion ) {
37
+ let mut group = c. benchmark_group( $group) ;
38
+ group. sample_size( SEARCH_SAMPLE_SIZE ) ;
39
+ group. warm_up_time( SEARCH_WARM_UP_TIME ) ;
40
+ group. measurement_time( SEARCH_MEASURE_TIME ) ;
41
+ group. sampling_mode( SamplingMode :: Flat ) ;
42
+ let mut patterns = load_file( $corpus) ;
43
+ patterns. sort_unstable( ) ;
44
+ let haystacks = load_file( $haystack) ;
45
+ $bench( & mut group, & patterns, & haystacks) ;
46
+ }
47
+ } ;
67
48
}
68
49
69
- fn criterion_unidic_find_overlapping ( c : & mut Criterion ) {
70
- let mut group = c. benchmark_group ( "unidic/find_overlapping" ) ;
71
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
72
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
73
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
74
- group. sampling_mode ( SamplingMode :: Flat ) ;
75
- let mut patterns = load_file ( "data/unidic/unidic" ) ;
76
- patterns. sort_unstable ( ) ;
77
- let haystacks = load_file ( "data/wagahaiwa_nekodearu.txt" ) ;
78
-
79
- add_find_overlapping_benches ( & mut group, & patterns, & haystacks) ;
80
- }
81
-
82
- fn criterion_words100000_find_overlapping ( c : & mut Criterion ) {
83
- let mut group = c. benchmark_group ( "words_100000/find_overlapping" ) ;
84
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
85
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
86
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
87
- group. sampling_mode ( SamplingMode :: Flat ) ;
88
- let mut patterns = load_file ( "data/words_100000" ) ;
89
- patterns. sort_unstable ( ) ;
90
- let haystacks = load_file ( "data/sherlock.txt" ) ;
91
-
92
- add_find_overlapping_benches ( & mut group, & patterns, & haystacks) ;
93
- }
50
+ define_build_bench ! ( criterion_unidic_build, "unidic/build" , "data/unidic/unidic" ) ;
51
+ define_build_bench ! (
52
+ criterion_words_100_build,
53
+ "words_100/build" ,
54
+ "data/words_100"
55
+ ) ;
56
+ define_build_bench ! (
57
+ criterion_words_5000_build,
58
+ "words_5000/build" ,
59
+ "data/words_5000"
60
+ ) ;
61
+ define_build_bench ! (
62
+ criterion_words_15000_build,
63
+ "words_15000/build" ,
64
+ "data/words_15000"
65
+ ) ;
66
+ define_build_bench ! (
67
+ criterion_words_100000_build,
68
+ "words_100000/build" ,
69
+ "data/words_100000"
70
+ ) ;
94
71
95
- fn criterion_unidic_leftmost_longest_find ( c : & mut Criterion ) {
96
- let mut group = c. benchmark_group ( "unidic/leftmost_longest_find" ) ;
97
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
98
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
99
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
100
- group. sampling_mode ( SamplingMode :: Flat ) ;
101
- let mut patterns = load_file ( "data/unidic/unidic" ) ;
102
- patterns. sort_unstable ( ) ;
103
- let haystacks = load_file ( "data/wagahaiwa_nekodearu.txt" ) ;
104
-
105
- add_leftmost_longest_find_benches ( & mut group, & patterns, & haystacks) ;
106
- }
72
+ define_find_bench ! (
73
+ criterion_unidic_find,
74
+ add_find_benches,
75
+ "unidic/find" ,
76
+ "data/unidic/unidic" ,
77
+ "data/wagahaiwa_nekodearu.txt"
78
+ ) ;
79
+ define_find_bench ! (
80
+ criterion_words_100_find,
81
+ add_find_benches,
82
+ "words_100/find" ,
83
+ "data/words_100" ,
84
+ "data/sherlock.txt"
85
+ ) ;
86
+ define_find_bench ! (
87
+ criterion_words_5000_find,
88
+ add_find_benches,
89
+ "words_5000/find" ,
90
+ "data/words_5000" ,
91
+ "data/sherlock.txt"
92
+ ) ;
93
+ define_find_bench ! (
94
+ criterion_words_15000_find,
95
+ add_find_benches,
96
+ "words_15000/find" ,
97
+ "data/words_15000" ,
98
+ "data/sherlock.txt"
99
+ ) ;
100
+ define_find_bench ! (
101
+ criterion_words_100000_find,
102
+ add_find_benches,
103
+ "words_100000/find" ,
104
+ "data/words_100000" ,
105
+ "data/sherlock.txt"
106
+ ) ;
107
107
108
- fn criterion_words100000_leftmost_longest_find ( c : & mut Criterion ) {
109
- let mut group = c. benchmark_group ( "words_100000/leftmost_longest_find" ) ;
110
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
111
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
112
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
113
- group. sampling_mode ( SamplingMode :: Flat ) ;
114
- let mut patterns = load_file ( "data/words_100000" ) ;
115
- patterns. sort_unstable ( ) ;
116
- let haystacks = load_file ( "data/sherlock.txt" ) ;
117
-
118
- add_leftmost_longest_find_benches ( & mut group, & patterns, & haystacks) ;
119
- }
108
+ define_find_bench ! (
109
+ criterion_unidic_find_overlapping,
110
+ add_find_overlapping_benches,
111
+ "unidic/find_overlapping" ,
112
+ "data/unidic/unidic" ,
113
+ "data/wagahaiwa_nekodearu.txt"
114
+ ) ;
115
+ define_find_bench ! (
116
+ criterion_words_100_find_overlapping,
117
+ add_find_overlapping_benches,
118
+ "words_100/find_overlapping" ,
119
+ "data/words_100" ,
120
+ "data/sherlock.txt"
121
+ ) ;
122
+ define_find_bench ! (
123
+ criterion_words_5000_find_overlapping,
124
+ add_find_overlapping_benches,
125
+ "words_5000/find_overlapping" ,
126
+ "data/words_5000" ,
127
+ "data/sherlock.txt"
128
+ ) ;
129
+ define_find_bench ! (
130
+ criterion_words_15000_find_overlapping,
131
+ add_find_overlapping_benches,
132
+ "words_15000/find_overlapping" ,
133
+ "data/words_15000" ,
134
+ "data/sherlock.txt"
135
+ ) ;
136
+ define_find_bench ! (
137
+ criterion_words_100000_find_overlapping,
138
+ add_find_overlapping_benches,
139
+ "words_100000/find_overlapping" ,
140
+ "data/words_100000" ,
141
+ "data/sherlock.txt"
142
+ ) ;
120
143
121
- fn criterion_unidic_leftmost_first_find ( c : & mut Criterion ) {
122
- let mut group = c. benchmark_group ( "unidic/leftmost_first_find" ) ;
123
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
124
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
125
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
126
- group. sampling_mode ( SamplingMode :: Flat ) ;
127
- let mut patterns = load_file ( "data/unidic/unidic" ) ;
128
- patterns. sort_unstable ( ) ;
129
- let haystacks = load_file ( "data/wagahaiwa_nekodearu.txt" ) ;
130
-
131
- add_leftmost_first_find_benches ( & mut group, & patterns, & haystacks) ;
132
- }
144
+ define_find_bench ! (
145
+ criterion_unidic_find_leftmost_longest,
146
+ add_find_leftmost_longest_benches,
147
+ "unidic/find_leftmost_longest" ,
148
+ "data/unidic/unidic" ,
149
+ "data/wagahaiwa_nekodearu.txt"
150
+ ) ;
151
+ define_find_bench ! (
152
+ criterion_words_100_find_leftmost_longest,
153
+ add_find_leftmost_longest_benches,
154
+ "words_100/find_leftmost_longest" ,
155
+ "data/words_100" ,
156
+ "data/sherlock.txt"
157
+ ) ;
158
+ define_find_bench ! (
159
+ criterion_words_5000_find_leftmost_longest,
160
+ add_find_leftmost_longest_benches,
161
+ "words_5000/find_leftmost_longest" ,
162
+ "data/words_5000" ,
163
+ "data/sherlock.txt"
164
+ ) ;
165
+ define_find_bench ! (
166
+ criterion_words_15000_find_leftmost_longest,
167
+ add_find_leftmost_longest_benches,
168
+ "words_15000/find_leftmost_longest" ,
169
+ "data/words_15000" ,
170
+ "data/sherlock.txt"
171
+ ) ;
172
+ define_find_bench ! (
173
+ criterion_words_100000_find_leftmost_longest,
174
+ add_find_leftmost_longest_benches,
175
+ "words_100000/find_leftmost_longest" ,
176
+ "data/words_100000" ,
177
+ "data/sherlock.txt"
178
+ ) ;
133
179
134
- fn criterion_words100000_leftmost_first_find ( c : & mut Criterion ) {
135
- let mut group = c. benchmark_group ( "words_100000/leftmost_first_find" ) ;
136
- group. sample_size ( SEARCH_SAMPLE_SIZE ) ;
137
- group. warm_up_time ( SEARCH_WARM_UP_TIME ) ;
138
- group. measurement_time ( SEARCH_MEASURE_TIME ) ;
139
- group. sampling_mode ( SamplingMode :: Flat ) ;
140
- let mut patterns = load_file ( "data/words_100000" ) ;
141
- patterns. sort_unstable ( ) ;
142
- let haystacks = load_file ( "data/sherlock.txt" ) ;
143
-
144
- add_leftmost_first_find_benches ( & mut group, & patterns, & haystacks) ;
145
- }
180
+ define_find_bench ! (
181
+ criterion_unidic_find_leftmost_first,
182
+ add_find_leftmost_first_benches,
183
+ "unidic/find_leftmost_first" ,
184
+ "data/unidic/unidic" ,
185
+ "data/wagahaiwa_nekodearu.txt"
186
+ ) ;
187
+ define_find_bench ! (
188
+ criterion_words_100_find_leftmost_first,
189
+ add_find_leftmost_first_benches,
190
+ "words_100/find_leftmost_first" ,
191
+ "data/words_100" ,
192
+ "data/sherlock.txt"
193
+ ) ;
194
+ define_find_bench ! (
195
+ criterion_words_5000_find_leftmost_first,
196
+ add_find_leftmost_first_benches,
197
+ "words_5000/find_leftmost_first" ,
198
+ "data/words_5000" ,
199
+ "data/sherlock.txt"
200
+ ) ;
201
+ define_find_bench ! (
202
+ criterion_words_15000_find_leftmost_first,
203
+ add_find_leftmost_first_benches,
204
+ "words_15000/find_leftmost_first" ,
205
+ "data/words_15000" ,
206
+ "data/sherlock.txt"
207
+ ) ;
208
+ define_find_bench ! (
209
+ criterion_words_100000_find_leftmost_first,
210
+ add_find_leftmost_first_benches,
211
+ "words_100000/find_leftmost_first" ,
212
+ "data/words_100000" ,
213
+ "data/sherlock.txt"
214
+ ) ;
146
215
147
216
fn add_build_benches ( group : & mut BenchmarkGroup < WallTime > , patterns : & [ String ] ) {
148
217
group. bench_function ( "daachorse" , |b| {
@@ -411,7 +480,7 @@ fn add_find_overlapping_benches(
411
480
} ) ;
412
481
}
413
482
414
- fn add_leftmost_longest_find_benches (
483
+ fn add_find_leftmost_longest_benches (
415
484
group : & mut BenchmarkGroup < WallTime > ,
416
485
patterns : & [ String ] ,
417
486
haystacks : & [ String ] ,
@@ -488,7 +557,7 @@ fn add_leftmost_longest_find_benches(
488
557
} ) ;
489
558
}
490
559
491
- fn add_leftmost_first_find_benches (
560
+ fn add_find_leftmost_first_benches (
492
561
group : & mut BenchmarkGroup < WallTime > ,
493
562
patterns : & [ String ] ,
494
563
haystacks : & [ String ] ,
@@ -605,13 +674,28 @@ criterion_group!(
605
674
benches,
606
675
criterion_unidic_find,
607
676
criterion_unidic_find_overlapping,
608
- criterion_unidic_leftmost_longest_find,
609
- criterion_unidic_leftmost_first_find,
677
+ criterion_unidic_find_leftmost_longest,
678
+ criterion_unidic_find_leftmost_first,
679
+ criterion_words_100_find,
680
+ criterion_words_100_find_overlapping,
681
+ criterion_words_100_find_leftmost_longest,
682
+ criterion_words_100_find_leftmost_first,
683
+ criterion_words_5000_find,
684
+ criterion_words_5000_find_overlapping,
685
+ criterion_words_5000_find_leftmost_longest,
686
+ criterion_words_5000_find_leftmost_first,
687
+ criterion_words_15000_find,
688
+ criterion_words_15000_find_overlapping,
689
+ criterion_words_15000_find_leftmost_longest,
690
+ criterion_words_15000_find_leftmost_first,
691
+ criterion_words_100000_find,
692
+ criterion_words_100000_find_overlapping,
693
+ criterion_words_100000_find_leftmost_longest,
694
+ criterion_words_100000_find_leftmost_first,
610
695
criterion_unidic_build,
611
- criterion_words100000_find,
612
- criterion_words100000_find_overlapping,
613
- criterion_words100000_leftmost_longest_find,
614
- criterion_words100000_leftmost_first_find,
615
- criterion_words100000_build,
696
+ criterion_words_100_build,
697
+ criterion_words_5000_build,
698
+ criterion_words_15000_build,
699
+ criterion_words_100000_build,
616
700
) ;
617
701
criterion_main ! ( benches) ;
0 commit comments