11
11
12
12
use std:: rand:: { Rng , task_rng} ;
13
13
use stdtest:: Bencher ;
14
+ use std:: iter:: repeat;
14
15
15
16
use regex:: { Regex , NoExpand } ;
16
17
@@ -22,38 +23,38 @@ fn bench_assert_match(b: &mut Bencher, re: Regex, text: &str) {
22
23
fn no_exponential ( b : & mut Bencher ) {
23
24
let n = 100 ;
24
25
let re = Regex :: new ( format ! ( "{}{}" ,
25
- "a?" . repeat ( n ) ,
26
- "a" . repeat ( n ) ) . as_slice ( ) ) . unwrap ( ) ;
27
- let text = "a" . repeat ( n ) ;
26
+ repeat ( "a?" ) . take ( n ) . collect :: < String > ( ) ,
27
+ repeat ( "a" ) . take ( n ) . collect :: < String > ( ) ) . as_slice ( ) ) . unwrap ( ) ;
28
+ let text = repeat ( "a" ) . take ( n ) . collect :: < String > ( ) ;
28
29
bench_assert_match ( b, re, text. as_slice ( ) ) ;
29
30
}
30
31
31
32
#[ bench]
32
33
fn literal ( b : & mut Bencher ) {
33
34
let re = regex ! ( "y" ) ;
34
- let text = format ! ( "{}y" , "x" . repeat ( 50 ) ) ;
35
+ let text = format ! ( "{}y" , repeat ( "x" ) . take ( 50 ) . collect :: < String > ( ) ) ;
35
36
bench_assert_match ( b, re, text. as_slice ( ) ) ;
36
37
}
37
38
38
39
#[ bench]
39
40
fn not_literal ( b : & mut Bencher ) {
40
41
let re = regex ! ( ".y" ) ;
41
- let text = format ! ( "{}y" , "x" . repeat ( 50 ) ) ;
42
+ let text = format ! ( "{}y" , repeat ( "x" ) . take ( 50 ) . collect :: < String > ( ) ) ;
42
43
bench_assert_match ( b, re, text. as_slice ( ) ) ;
43
44
}
44
45
45
46
#[ bench]
46
47
fn match_class ( b : & mut Bencher ) {
47
48
let re = regex ! ( "[abcdw]" ) ;
48
- let text = format ! ( "{}w" , "xxxx" . repeat ( 20 ) ) ;
49
+ let text = format ! ( "{}w" , repeat ( "xxxx" ) . take ( 20 ) . collect :: < String > ( ) ) ;
49
50
bench_assert_match ( b, re, text. as_slice ( ) ) ;
50
51
}
51
52
52
53
#[ bench]
53
54
fn match_class_in_range ( b : & mut Bencher ) {
54
55
// 'b' is between 'a' and 'c', so the class range checking doesn't help.
55
56
let re = regex ! ( "[ac]" ) ;
56
- let text = format ! ( "{}c" , "bbbb" . repeat ( 20 ) ) ;
57
+ let text = format ! ( "{}c" , repeat ( "bbbb" ) . take ( 20 ) . collect :: < String > ( ) ) ;
57
58
bench_assert_match ( b, re, text. as_slice ( ) ) ;
58
59
}
59
60
@@ -77,7 +78,7 @@ fn anchored_literal_short_non_match(b: &mut Bencher) {
77
78
#[ bench]
78
79
fn anchored_literal_long_non_match ( b : & mut Bencher ) {
79
80
let re = regex ! ( "^zbc(d|e)" ) ;
80
- let text = "abcdefghijklmnopqrstuvwxyz" . repeat ( 15 ) ;
81
+ let text = repeat ( "abcdefghijklmnopqrstuvwxyz" ) . take ( 15 ) . collect :: < String > ( ) ;
81
82
b. iter ( || re. is_match ( text. as_slice ( ) ) ) ;
82
83
}
83
84
@@ -91,7 +92,7 @@ fn anchored_literal_short_match(b: &mut Bencher) {
91
92
#[ bench]
92
93
fn anchored_literal_long_match ( b : & mut Bencher ) {
93
94
let re = regex ! ( "^.bc(d|e)" ) ;
94
- let text = "abcdefghijklmnopqrstuvwxyz" . repeat ( 15 ) ;
95
+ let text = repeat ( "abcdefghijklmnopqrstuvwxyz" ) . take ( 15 ) . collect :: < String > ( ) ;
95
96
b. iter ( || re. is_match ( text. as_slice ( ) ) ) ;
96
97
}
97
98
0 commit comments