black_box test strings in str.contains(str) benchmarks

This commit is contained in:
The 8472 2022-10-30 21:26:05 +01:00
parent 96ddd32c4b
commit 4844e5162c

View File

@ -123,7 +123,7 @@ fn bench_contains_short_short(b: &mut Bencher) {
let needle = "sit";
b.iter(|| {
assert!(haystack.contains(needle));
assert!(black_box(haystack).contains(black_box(needle)));
})
}
@ -167,7 +167,7 @@ malesuada sollicitudin quam eu fermentum.";
let needle = "english";
b.iter(|| {
assert!(!haystack.contains(needle));
assert!(!black_box(haystack).contains(black_box(needle)));
})
}
@ -177,7 +177,7 @@ fn bench_contains_bad_naive(b: &mut Bencher) {
let needle = "aaaaaaaab";
b.iter(|| {
assert!(!haystack.contains(needle));
assert!(!black_box(haystack).contains(black_box(needle)));
})
}
@ -187,7 +187,7 @@ fn bench_contains_equal(b: &mut Bencher) {
let needle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
b.iter(|| {
assert!(haystack.contains(needle));
assert!(black_box(haystack).contains(black_box(needle)));
})
}