Add benchmarks for start_with and ends_with
This commit is contained in:
parent
de7fefa04c
commit
3de1923d5d
2 changed files with 44 additions and 0 deletions
|
|
@ -11,4 +11,5 @@ mod hash;
|
|||
mod iter;
|
||||
mod num;
|
||||
mod ops;
|
||||
mod pattern;
|
||||
mod slice;
|
||||
|
|
|
|||
43
src/libcore/benches/pattern.rs
Normal file
43
src/libcore/benches/pattern.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use test::black_box;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn starts_with_char(b: &mut Bencher) {
|
||||
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
|
||||
b.iter(|| {
|
||||
for _ in 0..1024 {
|
||||
black_box(text.starts_with('k'));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn starts_with_str(b: &mut Bencher) {
|
||||
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
|
||||
b.iter(|| {
|
||||
for _ in 0..1024 {
|
||||
black_box(text.starts_with("k"));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
#[bench]
|
||||
fn ends_with_char(b: &mut Bencher) {
|
||||
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
|
||||
b.iter(|| {
|
||||
for _ in 0..1024 {
|
||||
black_box(text.ends_with('k'));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_str(b: &mut Bencher) {
|
||||
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
|
||||
b.iter(|| {
|
||||
for _ in 0..1024 {
|
||||
black_box(text.ends_with("k"));
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue