Skip to content

Commit

Permalink
Correct memchr implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Emann committed Oct 10, 2023
1 parent 8d4eba6 commit 3c1c91e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ fn xml5(c: &mut Criterion) {
});
group.bench_function("memchr", |b| {
b.iter(|| {
memchr::memchr3(b'<', b'>', b'&', haystack.as_bytes())
.or_else(|| memchr::memchr2(b'\'', b'"', haystack.as_bytes()))
match (
memchr::memchr3(b'<', b'>', b'&', haystack.as_bytes()),
memchr::memchr2(b'\'', b'"', haystack.as_bytes()),
) {
(None, rhs) => rhs,
(lhs, None) => lhs,
(Some(lhs), Some(rhs)) => Some(lhs.min(rhs)),
}
});
});
}
Expand Down Expand Up @@ -172,12 +178,15 @@ fn big_16(c: &mut Criterion) {
});
group.bench_function("memchr", |b| {
b.iter(|| {
memchr::memchr3(b'A', b'B', b'C', haystack.as_bytes())
.or_else(|| memchr::memchr3(b'D', b'E', b'F', haystack.as_bytes()))
.or_else(|| memchr::memchr3(b'G', b'H', b'I', haystack.as_bytes()))
.or_else(|| memchr::memchr3(b'J', b'K', b'L', haystack.as_bytes()))
.or_else(|| memchr::memchr3(b'M', b'N', b'O', haystack.as_bytes()))
.or_else(|| memchr::memchr(b'P', haystack.as_bytes()))
let indexes = [
memchr::memchr3(b'A', b'B', b'C', haystack.as_bytes()),
memchr::memchr3(b'D', b'E', b'F', haystack.as_bytes()),
memchr::memchr3(b'G', b'H', b'I', haystack.as_bytes()),
memchr::memchr3(b'J', b'K', b'L', haystack.as_bytes()),
memchr::memchr3(b'M', b'N', b'O', haystack.as_bytes()),
memchr::memchr(b'P', haystack.as_bytes()),
];
indexes.iter().copied().min_by_key(|x| x.unwrap_or(usize::MAX)).unwrap()
})
});
}
Expand Down

0 comments on commit 3c1c91e

Please sign in to comment.