Skip to content

Commit

Permalink
Add benchmarks for start_with and ends_with
Browse files Browse the repository at this point in the history
  • Loading branch information
ranma42 committed Dec 16, 2019
1 parent de7fefa commit 3de1923
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ mod hash;
mod iter;
mod num;
mod ops;
mod pattern;
mod slice;
43 changes: 43 additions & 0 deletions src/libcore/benches/pattern.rs
Original file line number Diff line number Diff line change
@@ -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"));
}
})
}

0 comments on commit 3de1923

Please sign in to comment.