forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for
start_with
and ends_with
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ mod hash; | |
mod iter; | ||
mod num; | ||
mod ops; | ||
mod pattern; | ||
mod slice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
}) | ||
} |