99// except according to those terms.
1010#![ allow( non_snake_case) ]
1111
12+ use std:: iter:: repeat;
1213use std:: rand:: { Rng , task_rng} ;
1314use stdtest:: Bencher ;
1415
@@ -21,39 +22,41 @@ fn bench_assert_match(b: &mut Bencher, re: Regex, text: &str) {
2122#[ bench]
2223fn no_exponential ( b : & mut Bencher ) {
2324 let n = 100 ;
24- let re = Regex :: new ( format ! ( "{}{}" ,
25- "a?" . repeat( n) ,
26- "a" . repeat( n) ) . as_slice ( ) ) . unwrap ( ) ;
27- let text = "a" . repeat ( n) ;
25+ let regex_string = format ! (
26+ "{}{}" ,
27+ repeat( "a?" ) . take( n) . collect:: <String >( ) ,
28+ repeat( "a" ) . take( n) . collect:: <String >( ) ) ;
29+ let re = Regex :: new ( regex_string. as_slice ( ) ) . unwrap ( ) ;
30+ let text: String = repeat ( "a" ) . take ( n) . collect ( ) ;
2831 bench_assert_match ( b, re, text. as_slice ( ) ) ;
2932}
3033
3134#[ bench]
3235fn literal ( b : & mut Bencher ) {
3336 let re = regex ! ( "y" ) ;
34- let text = format ! ( "{}y" , "x" . repeat ( 50 ) ) ;
37+ let text = format ! ( "{}y" , repeat ( "x" ) . take ( 50 ) . collect :: < String > ( ) ) ;
3538 bench_assert_match ( b, re, text. as_slice ( ) ) ;
3639}
3740
3841#[ bench]
3942fn not_literal ( b : & mut Bencher ) {
4043 let re = regex ! ( ".y" ) ;
41- let text = format ! ( "{}y" , "x" . repeat ( 50 ) ) ;
44+ let text = format ! ( "{}y" , repeat ( "x" ) . take ( 50 ) . collect :: < String > ( ) ) ;
4245 bench_assert_match ( b, re, text. as_slice ( ) ) ;
4346}
4447
4548#[ bench]
4649fn match_class ( b : & mut Bencher ) {
4750 let re = regex ! ( "[abcdw]" ) ;
48- let text = format ! ( "{}w" , "xxxx" . repeat ( 20 ) ) ;
51+ let text = format ! ( "{}w" , repeat ( "xxxx" ) . take ( 20 ) . collect :: < String > ( ) ) ;
4952 bench_assert_match ( b, re, text. as_slice ( ) ) ;
5053}
5154
5255#[ bench]
5356fn match_class_in_range ( b : & mut Bencher ) {
5457 // 'b' is between 'a' and 'c', so the class range checking doesn't help.
5558 let re = regex ! ( "[ac]" ) ;
56- let text = format ! ( "{}c" , "bbbb" . repeat ( 20 ) ) ;
59+ let text = format ! ( "{}c" , repeat ( "bbbb" ) . take ( 20 ) . collect :: < String > ( ) ) ;
5760 bench_assert_match ( b, re, text. as_slice ( ) ) ;
5861}
5962
@@ -77,7 +80,7 @@ fn anchored_literal_short_non_match(b: &mut Bencher) {
7780#[ bench]
7881fn anchored_literal_long_non_match ( b : & mut Bencher ) {
7982 let re = regex ! ( "^zbc(d|e)" ) ;
80- let text = "abcdefghijklmnopqrstuvwxyz" . repeat ( 15 ) ;
83+ let text: String = repeat ( "abcdefghijklmnopqrstuvwxyz" ) . take ( 15 ) . collect ( ) ;
8184 b. iter ( || re. is_match ( text. as_slice ( ) ) ) ;
8285}
8386
@@ -91,7 +94,7 @@ fn anchored_literal_short_match(b: &mut Bencher) {
9194#[ bench]
9295fn anchored_literal_long_match ( b : & mut Bencher ) {
9396 let re = regex ! ( "^.bc(d|e)" ) ;
94- let text = "abcdefghijklmnopqrstuvwxyz" . repeat ( 15 ) ;
97+ let text: String = repeat ( "abcdefghijklmnopqrstuvwxyz" ) . take ( 15 ) . collect ( ) ;
9598 b. iter ( || re. is_match ( text. as_slice ( ) ) ) ;
9699}
97100
0 commit comments