pattern-3 0.5.0

Needle API (née Pattern API 3.0), generalization of `std::str::pattern`
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
// Ensure our own implementation is not slower than the std implementation

#![feature(test)]

extern crate test;
extern crate pattern_3;

use test::Bencher;

macro_rules! make_test_inner {
    ($s:ident, $code:expr, $name:ident, $str:expr, $iters:expr) => {
        #[bench]
        fn $name(bencher: &mut Bencher) {
            let mut $s = $str;
            black_box(&mut $s);
            bencher.iter(|| for _ in 0..$iters { black_box($code); });
        }
    }
}

const LOREM_IPSUM: &str = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \
eros. Suspendisse sit amet magna mollis, mollis nunc luctus, imperdiet mi. Integer fringilla non \
sem ut lacinia. Fusce varius tortor a risus porttitor hendrerit. Morbi mauris dui, ultricies nec \
tempus vel, gravida nec quam.

In est dui, tincidunt sed tempus interdum, adipiscing laoreet ante. Etiam tempor, tellus quis \
sagittis interdum, nulla purus mattis sem, quis auctor erat odio ac tellus. In nec nunc sit amet \
diam volutpat molestie at sed ipsum. Vestibulum laoreet consequat vulputate. Integer accumsan \
lorem ac dignissim placerat. Suspendisse convallis faucibus lorem. Aliquam erat volutpat. In vel \
eleifend felis. Sed suscipit nulla lorem, sed mollis est sollicitudin et. Nam fermentum egestas \
interdum. Curabitur ut nisi justo.

Sed sollicitudin ipsum tellus, ut condimentum leo eleifend nec. Cras ut velit ante. Phasellus nec \
mollis odio. Mauris molestie erat in arcu mattis, at aliquet dolor vehicula. Quisque malesuada \
lectus sit amet nisi pretium, a condimentum ipsum porta. Morbi at dapibus diam. Praesent egestas \
est sed risus elementum, eu rutrum metus ultrices. Etiam fermentum consectetur magna, id rutrum \
felis accumsan a. Aliquam ut pellentesque libero. Sed mi nulla, lobortis eu tortor id, suscipit \
ultricies neque. Morbi iaculis sit amet risus at iaculis. Praesent eget ligula quis turpis \
feugiat suscipit vel non arcu. Interdum et malesuada fames ac ante ipsum primis in faucibus. \
Aliquam sit amet placerat lorem.

Cras a lacus vel ante posuere elementum. Nunc est leo, bibendum ut facilisis vel, bibendum at \
mauris. Nullam adipiscing diam vel odio ornare, luctus adipiscing mi luctus. Nulla facilisi. \
Mauris adipiscing bibendum neque, quis adipiscing lectus tempus et. Sed feugiat erat et nisl \
lobortis pharetra. Donec vitae erat enim. Nullam sit amet felis et quam lacinia tincidunt. Aliquam \
suscipit dapibus urna. Sed volutpat urna in magna pulvinar volutpat. Phasellus nec tellus ac diam \
cursus accumsan.

Nam lectus enim, dapibus non nisi tempor, consectetur convallis massa. Maecenas eleifend dictum \
feugiat. Etiam quis mauris vel risus luctus mattis a a nunc. Nullam orci quam, imperdiet id \
vehicula in, porttitor ut nibh. Duis sagittis adipiscing nisl vitae congue. Donec mollis risus eu \
leo suscipit, varius porttitor nulla porta. Pellentesque ut sem nec nisi euismod vehicula. Nulla \
malesuada sollicitudin quam eu fermentum!";

macro_rules! make_test {
    ($name:ident, $s:ident, $code:expr) => {
        make_test!($name, $s, $code, 1);
    };
    ($name:ident, $s:ident, $code:expr, $iters:expr) => {
        mod $name {
            use test::Bencher;
            use test::black_box;

            // Short strings: 65 bytes each
            make_test_inner!($s, $code, short_ascii,
                "Mary had a little lamb, Little lamb Mary had a littl lamb, lamb!", $iters);
            make_test_inner!($s, $code, short_mixed,
                "ศไทย中华Việt Nam; Mary had a little lamb, Little lam!", $iters);
            make_test_inner!($s, $code, short_pile_of_poo,
                "💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩!", $iters);
            make_test_inner!($s, $code, long_lorem_ipsum, ::LOREM_IPSUM, $iters);
        }
    }
}

// std:
//     long_lorem_ipsum:    ~260 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~20 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
// pat3:
//     long_lorem_ipsum:     ~50 ns/iter
//     short_ascii:          ~15 ns/iter
//     short_mixed:          ~15 ns/iter
//     short_pile_of_pool:   ~15 ns/iter
make_test!(std_contains_bang_char, s, s.contains('!'));
make_test!(pat3_contains_bang_char, s, ::pattern_3::ext::contains(s, '!'));

// std:
//     long_lorem_ipsum:    ~270 ns/iter
//     short_ascii:          ~10 ns/iter
//     short_mixed:          ~10 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
// pat3:
//     long_lorem_ipsum:     ~50 ns/iter
//     short_ascii:          ~10 ns/iter
//     short_mixed:          ~10 ns/iter
//     short_pile_of_pool:   ~10 ns/iter
make_test!(std_find_underscore_char, s, s.find('_'));
make_test!(pat3_find_underscore_char, s, ::pattern_3::ext::find(s, '_'));

// std:
//     long_lorem_ipsum:    ~280 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~20 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
// pat3:
//     long_lorem_ipsum:    ~210 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~20 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
make_test!(std_rfind_underscore_char, s, s.rfind('_'));
make_test!(pat3_rfind_underscore_char, s, ::pattern_3::ext::rfind(s, '_'));

// std:
//     long_lorem_ipsum:    ~260 ns/iter
//     short_ascii:          ~10 ns/iter
//     short_mixed:          ~10 ns/iter
//     short_pile_of_pool:   ~10 ns/iter
// pat3:
//     long_lorem_ipsum:     ~55 ns/iter
//     short_ascii:          ~10 ns/iter
//     short_mixed:          ~10 ns/iter
//     short_pile_of_pool:   ~10 ns/iter
make_test!(std_find_zzz_char, s, s.find('\u{1F4A4}'));
make_test!(pat3_find_zzz_char, s, ::pattern_3::ext::find(s, '\u{1F4A4}'));

// std:
//     long_lorem_ipsum:    ~280 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~20 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
// pat3:
//     long_lorem_ipsum:    ~220 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~20 ns/iter
//     short_pile_of_pool:   ~20 ns/iter
make_test!(std_rfind_zzz_char, s, s.rfind('\u{1F4A4}'));
make_test!(pat3_rfind_zzz_char, s, ::pattern_3::ext::rfind(s, '\u{1F4A4}'));

// std:
//     long_lorem_ipsum:    ~300 ns/iter
//     short_ascii:         ~300 ns/iter
//     short_mixed:         ~750 ns/iter
//     short_pile_of_pool:  ~840 ns/iter
// pat3:
//     long_lorem_ipsum:    ~180 ns/iter
//     short_ascii:         ~180 ns/iter
//     short_mixed:         ~180 ns/iter
//     short_pile_of_pool:  ~180 ns/iter
make_test!(std_starts_with_ascii_char, s, s.starts_with('/'), 256);
make_test!(pat3_starts_with_ascii_char, s, ::pattern_3::ext::starts_with(s, '/'), 256);

// std:
//     long_lorem_ipsum:    ~300 ns/iter
//     short_ascii:         ~300 ns/iter
//     short_mixed:         ~750 ns/iter
//     short_pile_of_pool:  ~920 ns/iter
// pat3:
//     long_lorem_ipsum:    ~180 ns/iter
//     short_ascii:         ~180 ns/iter
//     short_mixed:         ~680 ns/iter
//     short_pile_of_pool:  ~870 ns/iter
make_test!(std_starts_with_any_ascii_char, s, s.starts_with(|c: char| c.is_ascii()), 256);
make_test!(pat3_starts_with_any_ascii_char, s, ::pattern_3::ext::starts_with(s, |c: char| c.is_ascii()), 256);

// std:
//     long_lorem_ipsum:    ~340 ns/iter
//     short_ascii:         ~340 ns/iter
//     short_mixed:         ~200 ns/iter
//     short_pile_of_pool:  ~670 ns/iter
// pat3:
//     long_lorem_ipsum:    ~260 ns/iter
//     short_ascii:         ~270 ns/iter
//     short_mixed:         ~260 ns/iter [*slower*] (o_O?)
//     short_pile_of_pool:  ~260 ns/iter
make_test!(std_starts_with_string, s, s.starts_with("💩💩"), 256);
make_test!(pat3_starts_with_string, s, ::pattern_3::ext::starts_with(s, "💩💩"), 256);

// std:
//     long_lorem_ipsum:    ~330 ns/iter
//     short_ascii:         ~330 ns/iter
//     short_mixed:         ~830 ns/iter
//     short_pile_of_pool:  ~910 ns/iter
// pat3:
//     long_lorem_ipsum:    ~310 ns/iter
//     short_ascii:         ~310 ns/iter
//     short_mixed:         ~310 ns/iter
//     short_pile_of_pool:  ~310 ns/iter
make_test!(std_starts_with_unichar, s, s.starts_with('\u{1F4A4}'), 256);
make_test!(pat3_starts_with_unichar, s, ::pattern_3::ext::starts_with(s, '\u{1F4A4}'), 256);

// std:
//     long_lorem_ipsum:    ~260 ns/iter
//     short_ascii:         ~260 ns/iter
//     short_mixed:         ~260 ns/iter
//     short_pile_of_pool:  ~260 ns/iter
// pat3:
//     long_lorem_ipsum:    ~180 ns/iter
//     short_ascii:         ~180 ns/iter
//     short_mixed:         ~180 ns/iter
//     short_pile_of_pool:  ~180 ns/iter
make_test!(std_ends_with_ascii_char, s, s.ends_with('/'), 256);
make_test!(pat3_ends_with_ascii_char, s, ::pattern_3::ext::ends_with(s, '/'), 256);

// std:
//     long_lorem_ipsum:    ~210 ns/iter
//     short_ascii:         ~210 ns/iter
//     short_mixed:         ~210 ns/iter
//     short_pile_of_pool:  ~210 ns/iter
// pat3:
//     long_lorem_ipsum:    ~200 ns/iter
//     short_ascii:         ~200 ns/iter
//     short_mixed:         ~200 ns/iter
//     short_pile_of_pool:  ~200 ns/iter
make_test!(std_ends_with_unichar, s, s.ends_with('\u{1F4A4}'), 256);
make_test!(pat3_ends_with_unichar, s, ::pattern_3::ext::ends_with(s, '\u{1F4A4}'), 256);

// std:
//     long_lorem_ipsum:     ~20 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~60 ns/iter
//     short_pile_of_pool: ~1000 ns/iter
// pat3:
//     long_lorem_ipsum:     ~20 ns/iter
//     short_ascii:          ~20 ns/iter
//     short_mixed:          ~80 ns/iter [*slower*]
//     short_pile_of_pool: ~1000 ns/iter
make_test!(std_trim_left_unichar, s, s.trim_left_matches('💩'), 16);
make_test!(pat3_trim_left_unichar, s, ::pattern_3::ext::trim_start(s, '💩'), 16);

// std:
//     long_lorem_ipsum:     ~60 ns/iter
//     short_ascii:          ~60 ns/iter
//     short_mixed:          ~60 ns/iter
//     short_pile_of_pool:   ~90 ns/iter
// pat3:
//     long_lorem_ipsum:     ~40 ns/iter
//     short_ascii:          ~40 ns/iter
//     short_mixed:          ~50 ns/iter
//     short_pile_of_pool:   ~90 ns/iter
make_test!(std_trim_right_unichar, s, s.trim_right_matches('!'), 16);
make_test!(pat3_trim_right_unichar, s, ::pattern_3::ext::trim_end(s, '!'), 16);

make_test!(std_trim_both_unichar, s, s.trim_matches('💩'), 16);
make_test!(pat3_trim_both_unichar, s, ::pattern_3::ext::trim(s, '💩'), 16);

// std:
//     long_lorem_ipsum:   ~1200 ns/iter
//     short_ascii:        ~1200 ns/iter
//     short_mixed:        ~1200 ns/iter
//     short_pile_of_pool: ~3000 ns/iter
// pat3:
//     long_lorem_ipsum:     ~30 ns/iter
//     short_ascii:          ~30 ns/iter
//     short_mixed:          ~30 ns/iter
//     short_pile_of_pool:  ~110 ns/iter
make_test!(std_trim_left_unicode_string, s, s.trim_left_matches("💩💩"), 16);
make_test!(pat3_trim_left_unicode_string, s, ::pattern_3::ext::trim_start(s, "💩💩"), 16);

// std:
//     long_lorem_ipsum:    ~640 ns/iter
//     short_ascii:         ~470 ns/iter
//     short_mixed:         ~640 ns/iter
//     short_pile_of_pool:  ~500 ns/iter
// pat3:
//     long_lorem_ipsum:     ~30 ns/iter
//     short_ascii:          ~15 ns/iter
//     short_mixed:          ~30 ns/iter
//     short_pile_of_pool:   ~15 ns/iter
make_test!(std_trim_right_ascii_string, s, s.trim_right_matches("m!"), 16);
make_test!(pat3_trim_right_ascii_string, s, ::pattern_3::ext::trim_end(s, "m!"), 16);

// std:
//     long_lorem_ipsum:    ~170 ns/iter
//     short_ascii:         ~140 ns/iter
//     short_mixed:         ~500 ns/iter
//     short_pile_of_pool: ~1300 ns/iter
// pat3:
//     long_lorem_ipsum:    ~100 ns/iter
//     short_ascii:          ~90 ns/iter
//     short_mixed:         ~400 ns/iter
//     short_pile_of_pool: ~1000 ns/iter
make_test!(std_find_fn, s, s.find(|c: char| c == ' '), 16);
make_test!(pat3_find_fn, s, ::pattern_3::ext::find(s, |c: char| c == ' '), 16);

// std:
//     long_lorem_ipsum:    ~190 ns/iter
//     short_ascii:         ~110 ns/iter
//     short_mixed:         ~100 ns/iter
//     short_pile_of_pool:  ~870 ns/iter
// pat3:
//     long_lorem_ipsum:    ~220 ns/iter
//     short_ascii:         ~130 ns/iter
//     short_mixed:         ~110 ns/iter
//     short_pile_of_pool:  ~980 ns/iter
make_test!(std_rfind_fn, s, s.rfind(|c: char| c == ' '), 16);
make_test!(pat3_rfind_fn, s, ::pattern_3::ext::rfind(s, |c: char| c == ' '), 16);

// std:
//     long_lorem_ipsum:   ~3300 ns/iter
//     short_ascii:          ~90 ns/iter
//     short_mixed:           ~4 ns/iter
//     short_pile_of_pool:    ~5 ns/iter
// pat3:
//     long_lorem_ipsum:   ~1700 ns/iter
//     short_ascii:          ~60 ns/iter
//     short_mixed:           ~5 ns/iter
//     short_pile_of_pool:    ~7 ns/iter
make_test!(std_trim_left_ascii_char, s, s.trim_left_matches(|c: char| c.is_ascii()));
make_test!(pat3_trim_left_ascii_char, s, ::pattern_3::ext::trim_start(s, |c: char| c.is_ascii()));

// std:
//     long_lorem_ipsum:   ~1600 ns/iter
//     short_ascii:          ~50 ns/iter
//     short_mixed:          ~40 ns/iter
//     short_pile_of_pool:    ~6 ns/iter
// pat3:
//     long_lorem_ipsum:   ~1300 ns/iter
//     short_ascii:          ~50 ns/iter
//     short_mixed:          ~40 ns/iter
//     short_pile_of_pool:    ~5 ns/iter
make_test!(std_trim_right_ascii_char, s, s.trim_right_matches(|c: char| c.is_ascii()));
make_test!(pat3_trim_right_ascii_char, s, ::pattern_3::ext::trim_end(s, |c: char| c.is_ascii()));

make_test!(std_trim_both_ascii_char, s, s.trim_matches(|c: char| c.is_ascii()));
make_test!(pat3_trim_both_ascii_char, s, ::pattern_3::ext::trim(s, |c: char| c.is_ascii()));

// std:
//     long_lorem_ipsum:   ~5200 ns/iter
//     short_ascii:         ~130 ns/iter
//     short_mixed:         ~130 ns/iter
//     short_pile_of_pool:  ~100 ns/iter
// pat3:
//     long_lorem_ipsum:   ~3900 ns/iter
//     short_ascii:          ~90 ns/iter
//     short_mixed:          ~90 ns/iter
//     short_pile_of_pool:   ~90 ns/iter
make_test!(std_contains_bang_str, s, s.contains("!"));
make_test!(pat3_contains_bang_str, s, ::pattern_3::ext::contains(s, "!"));

// std:
//     long_lorem_ipsum:   ~6200 ns/iter
//     short_ascii:         ~200 ns/iter
//     short_mixed:         ~170 ns/iter
//     short_pile_of_pool:  ~110 ns/iter
// pat3:
//     long_lorem_ipsum:   ~5700 ns/iter
//     short_ascii:         ~180 ns/iter
//     short_mixed:         ~160 ns/iter
//     short_pile_of_pool:  ~110 ns/iter
make_test!(std_match_indices_a_str, s, s.match_indices("a").count());
make_test!(pat3_match_indices_a_str, s, ::pattern_3::ext::match_indices(s, "a").count());

// std:
//     long_lorem_ipsum:  ~23000 ns/iter
//     short_ascii:         ~610 ns/iter
//     short_mixed:         ~510 ns/iter
//     short_pile_of_pool:  ~290 ns/iter
// pat3:
//     long_lorem_ipsum:  ~17000 ns/iter
//     short_ascii:         ~460 ns/iter
//     short_mixed:         ~400 ns/iter
//     short_pile_of_pool:  ~240 ns/iter
make_test!(std_match_indices_empty, s, s.match_indices("").count());
make_test!(pat3_match_indices_empty, s, ::pattern_3::ext::match_indices(s, "").count());

// std:
//     long_lorem_ipsum:   ~6100 ns/iter
//     short_ascii:         ~200 ns/iter
//     short_mixed:         ~170 ns/iter
//     short_pile_of_pool:  ~100 ns/iter
// pat3:
//     long_lorem_ipsum:   ~5800 ns/iter
//     short_ascii:         ~180 ns/iter
//     short_mixed:         ~160 ns/iter
//     short_pile_of_pool:  ~110 ns/iter
make_test!(std_split_a_str, s, s.split("a").count());
make_test!(pat3_split_a_str, s, ::pattern_3::ext::split(s, "a").count());

// std:
//     long_lorem_ipsum:   ~9300 ns/iter
//     short_ascii:         ~200 ns/iter
//     short_mixed:         ~190 ns/iter
//     short_pile_of_pool:  ~100 ns/iter
// pat3:
//     long_lorem_ipsum:   ~8500 ns/iter
//     short_ascii:         ~200 ns/iter
//     short_mixed:         ~170 ns/iter
//     short_pile_of_pool:  ~100 ns/iter
make_test!(std_split_space_str, s, s.split(" ").count());
make_test!(pat3_split_space_str, s, ::pattern_3::ext::split(s, " ").count());

// std:
//     long_lorem_ipsum:   ~2400 ns/iter
//     short_ascii:         ~100 ns/iter
//     short_mixed:          ~80 ns/iter
//     short_pile_of_pool:   ~70 ns/iter
// pat3:
//     long_lorem_ipsum:   ~1800 ns/iter
//     short_ascii:          ~90 ns/iter
//     short_mixed:          ~70 ns/iter
//     short_pile_of_pool:   ~60 ns/iter
make_test!(std_split_ad_str, s, s.split("ad").count());
make_test!(pat3_split_ad_str, s, ::pattern_3::ext::split(s, "ad").count());

// std:     ~60 ns/iter
// pat3:    ~30 ns/iter
#[bench]
fn std_split_unicode_ascii(b: &mut Bencher) {
    let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
    b.iter(|| assert_eq!(s.split('V').count(), 3));
}
#[bench]
fn pat3_split_unicode_ascii(b: &mut Bencher) {
    let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
    b.iter(|| assert_eq!(pattern_3::ext::split(s, 'V').count(), 3));
}

// std:     ~120 ns/iter
// pat3:     ~80 ns/iter
#[bench]
fn std_split_ascii(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    b.iter(|| assert_eq!(s.split(' ').count(), len));
}
#[bench]
fn pat3_split_ascii(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    b.iter(|| assert_eq!(pattern_3::ext::split(s, ' ').count(), len));
}

// std:    ~110 ns/iter
// pat3:   ~180 ns/iter [*slower*]
#[bench]
fn std_split_extern_fn(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    #[inline(never)]
    fn pred(c: char) -> bool { c == ' ' }
    b.iter(|| assert_eq!(s.split(pred).count(), len));
}
#[bench]
fn pat3_split_extern_fn(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    #[inline(never)]
    fn pred(c: char) -> bool { c == ' ' }
    b.iter(|| assert_eq!(pattern_3::ext::split(s, pred).count(), len));
}

// std:     ~40 ns/iter
// pat3:    ~45 ns/iter [*slower*]
#[bench]
fn std_split_closure(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    b.iter(|| assert_eq!(s.split(|c: char| c == ' ').count(), len));
}
#[bench]
fn pat3_split_closure(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    b.iter(|| assert_eq!(::pattern_3::ext::split(s, |c: char| c == ' ').count(), len));
}

// std:     ~120 ns/iter
// pat3:    ~150 ns/iter [*slower*]
#[bench]
fn std_split_slice(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    let c: &[char] = &[' '];
    b.iter(|| assert_eq!(s.split(c).count(), len));
}
#[bench]
fn pat3_split_slice(b: &mut Bencher) {
    let s = "Mary had a little lamb, Little lamb, little-lamb.";
    let len = s.split(' ').count();
    let c: &[char] = &[' '];
    b.iter(|| assert_eq!(::pattern_3::ext::split(s, c).count(), len));
}

// std:     ~40 ns/iter
// pat3:    ~40 ns/iter
#[bench]
fn std_contains_short_short(b: &mut Bencher) {
    let haystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    let needle = "sit";
    b.iter(|| assert!(haystack.contains(needle)))
}
#[bench]
fn pat3_contains_short_short(b: &mut Bencher) {
    let haystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    let needle = "sit";
    b.iter(|| assert!(::pattern_3::ext::contains(haystack, needle)))
}

// std:    ~1000 ns/iter
// pat3:    ~710 ns/iter
#[bench]
fn std_contains_short_long(b: &mut Bencher) {
    let haystack = LOREM_IPSUM;
    let needle = "english";
    b.iter(|| assert!(!haystack.contains(needle)));
}
#[bench]
fn pat3_contains_short_long(b: &mut Bencher) {
    let haystack = LOREM_IPSUM;
    let needle = "english";
    b.iter(|| assert!(!::pattern_3::ext::contains(haystack, needle)));
}

// std:     ~200 ns/iter
// pat3:    ~170 ns/iter
#[bench]
fn std_contains_bad_naive(b: &mut Bencher) {
    let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    let needle = "aaaaaaaab";

    b.iter(|| assert!(!haystack.contains(needle)));
}
#[bench]
fn pat3_contains_bad_naive(b: &mut Bencher) {
    let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    let needle = "aaaaaaaab";
    b.iter(|| assert!(!::pattern_3::ext::contains(haystack, needle)));
}

// std:     ~280 ns/iter
// pat3:    ~300 ns/iter [*slower*]
#[bench]
fn std_contains_equal(b: &mut Bencher) {
    let haystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    let needle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    b.iter(|| assert!(haystack.contains(needle)))
}
#[bench]
fn pat3_contains_equal(b: &mut Bencher) {
    let haystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    let needle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    b.iter(|| assert!(::pattern_3::ext::contains(haystack, needle)))
}