• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use test::black_box;
2 use test::Bencher;
3 
4 #[bench]
starts_with_char(b: &mut Bencher)5 fn starts_with_char(b: &mut Bencher) {
6     let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
7     b.iter(|| {
8         for _ in 0..1024 {
9             black_box(text.starts_with('k'));
10         }
11     })
12 }
13 
14 #[bench]
starts_with_str(b: &mut Bencher)15 fn starts_with_str(b: &mut Bencher) {
16     let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
17     b.iter(|| {
18         for _ in 0..1024 {
19             black_box(text.starts_with("k"));
20         }
21     })
22 }
23 
24 #[bench]
ends_with_char(b: &mut Bencher)25 fn ends_with_char(b: &mut Bencher) {
26     let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
27     b.iter(|| {
28         for _ in 0..1024 {
29             black_box(text.ends_with('k'));
30         }
31     })
32 }
33 
34 #[bench]
ends_with_str(b: &mut Bencher)35 fn ends_with_str(b: &mut Bencher) {
36     let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
37     b.iter(|| {
38         for _ in 0..1024 {
39             black_box(text.ends_with("k"));
40         }
41     })
42 }
43