Skip to content

Commit 3de1923

Browse files
committed
Add benchmarks for start_with and ends_with
1 parent de7fefa commit 3de1923

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/libcore/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ mod hash;
1111
mod iter;
1212
mod num;
1313
mod ops;
14+
mod pattern;
1415
mod slice;

src/libcore/benches/pattern.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use test::black_box;
2+
use test::Bencher;
3+
4+
#[bench]
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]
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+
25+
#[bench]
26+
fn ends_with_char(b: &mut Bencher) {
27+
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
28+
b.iter(|| {
29+
for _ in 0..1024 {
30+
black_box(text.ends_with('k'));
31+
}
32+
})
33+
}
34+
35+
#[bench]
36+
fn ends_with_str(b: &mut Bencher) {
37+
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
38+
b.iter(|| {
39+
for _ in 0..1024 {
40+
black_box(text.ends_with("k"));
41+
}
42+
})
43+
}

0 commit comments

Comments
 (0)