diff options
| author | Andrea Canciani <ranma42@gmail.com> | 2019-12-16 15:33:16 +0100 |
|---|---|---|
| committer | Andrea Canciani <ranma42@gmail.com> | 2019-12-16 15:33:16 +0100 |
| commit | 3de1923d5d3aad5c4bb0914f054e950bf166aa00 (patch) | |
| tree | 5ae8c335da39a6b9ac0a67a87cb5d40421f88ceb | |
| parent | de7fefa04c74ecaa7618c910a74ae1cf62affa8e (diff) | |
| download | rust-3de1923d5d3aad5c4bb0914f054e950bf166aa00.tar.gz rust-3de1923d5d3aad5c4bb0914f054e950bf166aa00.zip | |
Add benchmarks for `start_with` and `ends_with`
| -rw-r--r-- | src/libcore/benches/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/benches/pattern.rs | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/libcore/benches/lib.rs b/src/libcore/benches/lib.rs index 6932c7fe221..570fc4ab933 100644 --- a/src/libcore/benches/lib.rs +++ b/src/libcore/benches/lib.rs @@ -11,4 +11,5 @@ mod hash; mod iter; mod num; mod ops; +mod pattern; mod slice; diff --git a/src/libcore/benches/pattern.rs b/src/libcore/benches/pattern.rs new file mode 100644 index 00000000000..a49490cec12 --- /dev/null +++ b/src/libcore/benches/pattern.rs @@ -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")); + } + }) +} |
