Relocate bench and use str corpora for data
Add #[inline(always)] to inner function and check not for filecheck test
This commit is contained in:
parent
7b88f48b53
commit
a5ba24843d
6 changed files with 50 additions and 58 deletions
|
|
@ -103,6 +103,7 @@ impl [u8] {
|
|||
let (other_chunks, _) = other.as_chunks::<N>();
|
||||
|
||||
// Branchless check to encourage auto-vectorization
|
||||
#[inline(always)]
|
||||
const fn eq_ignore_ascii_inner(lhs: &[u8; N], rhs: &[u8; N]) -> bool {
|
||||
let mut equal_ascii = true;
|
||||
let mut j = 0;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
mod eq_ignore_ascii_case;
|
||||
mod is_ascii;
|
||||
|
||||
// Lower-case ASCII 'a' is the first byte that has its highest bit set
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_str_under_8_bytes_eq(b: &mut Bencher) {
|
||||
let s = "foo";
|
||||
let other = "FOo";
|
||||
b.iter(|| {
|
||||
assert!(s.eq_ignore_ascii_case(other));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_of_8_bytes_eq(b: &mut Bencher) {
|
||||
let s = "foobar78";
|
||||
let other = "FOObAr78";
|
||||
b.iter(|| {
|
||||
assert!(s.eq_ignore_ascii_case(other));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_17_bytes_eq(b: &mut Bencher) {
|
||||
let s = "performance-criti";
|
||||
let other = "performANce-cRIti";
|
||||
b.iter(|| {
|
||||
assert!(s.eq_ignore_ascii_case(other));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_31_bytes_eq(b: &mut Bencher) {
|
||||
let s = "foobarbazquux02foobarbazquux025";
|
||||
let other = "fooBARbazQuuX02fooBARbazQuuX025";
|
||||
b.iter(|| {
|
||||
assert!(s.eq_ignore_ascii_case(other));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_long_str_eq(b: &mut Bencher) {
|
||||
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
|
||||
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
|
||||
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
|
||||
officia deserunt mollit anim id est laborum.";
|
||||
let other = "Lorem ipsum dolor sit amet, CONSECTETUR adipisicing elit, sed do eiusmod tempor \
|
||||
incididunt ut labore et dolore MAGNA aliqua. Ut enim ad MINIM veniam, quis nostrud \
|
||||
exercitation ullamco LABORIS nisi ut aliquip ex ea commodo consequat. Duis aute \
|
||||
irure dolor in reprehenderit in voluptate velit esse cillum DOLORE eu fugiat nulla \
|
||||
pariatur. Excepteur sint occaecat CUPIDATAT non proident, sunt in culpa qui \
|
||||
officia deserunt mollit anim id est laborum.";
|
||||
b.iter(|| {
|
||||
assert!(s.eq_ignore_ascii_case(other));
|
||||
})
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ use test::{Bencher, black_box};
|
|||
mod char_count;
|
||||
mod corpora;
|
||||
mod debug;
|
||||
mod eq_ignore_ascii_case;
|
||||
mod iter;
|
||||
|
||||
#[bench]
|
||||
|
|
|
|||
45
library/coretests/benches/str/eq_ignore_ascii_case.rs
Normal file
45
library/coretests/benches/str/eq_ignore_ascii_case.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use test::{Bencher, black_box};
|
||||
|
||||
use super::corpora::*;
|
||||
|
||||
#[bench]
|
||||
fn bench_str_under_8_bytes_eq(b: &mut Bencher) {
|
||||
let s = black_box("foo");
|
||||
let other = black_box("foo");
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_of_8_bytes_eq(b: &mut Bencher) {
|
||||
let s = black_box(en::TINY);
|
||||
let other = black_box(en::TINY);
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_17_bytes_eq(b: &mut Bencher) {
|
||||
let s = black_box(&en::SMALL[..17]);
|
||||
let other = black_box(&en::SMALL[..17]);
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_31_bytes_eq(b: &mut Bencher) {
|
||||
let s = black_box(&en::SMALL[..31]);
|
||||
let other = black_box(&en::SMALL[..31]);
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_medium_str_eq(b: &mut Bencher) {
|
||||
let s = black_box(en::MEDIUM);
|
||||
let other = black_box(en::MEDIUM);
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_large_str_eq(b: &mut Bencher) {
|
||||
let s = black_box(en::LARGE);
|
||||
let other = black_box(en::LARGE);
|
||||
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
|
||||
}
|
||||
|
|
@ -2,13 +2,15 @@
|
|||
//@ only-x86_64
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Ensure that the optimized variant of the function gets auto-vectorized.
|
||||
// Ensure that the optimized variant of the function gets auto-vectorized and
|
||||
// that the inner helper function is inlined.
|
||||
// CHECK-LABEL: @eq_ignore_ascii_case_autovectorized
|
||||
#[no_mangle]
|
||||
pub fn eq_ignore_ascii_case_autovectorized(s: &str, other: &str) -> bool {
|
||||
// CHECK: load <16 x i8>
|
||||
// CHECK: load <16 x i8>
|
||||
// CHECK: bitcast <16 x i1>
|
||||
// CHECK-NOT: call {{.*}}eq_ignore_ascii_inner
|
||||
// CHECK-NOT: panic
|
||||
s.eq_ignore_ascii_case(other)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue