Skip to content

Commit b3b9b8c

Browse files
committed
Add benchmarks for memchr::memmem:find
Results: ``` short_haystack/memchr::memmem::find time: [1671827971 instructions 1671827976 instructions 1671827981 instructions] long_haystack/memchr::memmem::find time: [256235298 instructions 256235300 instructions 256235303 instructions] random_haystack/memchr::memmem::find time: [3276143 instructions 3276143 instructions 3276143 instructions] short_haystack/DynamicAvx2Searcher::search_in time: [1010100472 instructions 1010100481 instructions 1010100491 instructions] long_haystack/DynamicAvx2Searcher::search_in time: [239679929 instructions 239679930 instructions 239679931 instructions] random_haystack/DynamicAvx2Searcher::search_in time: [1574708 instructions 1574708 instructions 1574708 instructions] ``` Summary: * `short_haystack`: +65% instructions for `memchr::memmem:find` * `long_haystack`: +6% instructions for `memchr::memmem:find` * `random_haystack`: +108% instructions for `memchr::memmem:find`
1 parent 7123a27 commit b3b9b8c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

bench/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ publish = false
66

77
[dependencies]
88
criterion = "0.3"
9+
memchr = "2.4"
910
memmem = "0.1"
1011
sliceslice = { path = ".." }
1112
sse4-strstr = { path = "sse4-strstr", optional = true }

bench/benches/i386.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ fn search_short_haystack<M: Measurement>(c: &mut Criterion<M>) {
5656
});
5757
});
5858

59+
group.bench_function("memchr::memmem::find", |b| {
60+
b.iter(|| {
61+
for (i, needle) in needles.iter().enumerate() {
62+
for haystack in &needles[i..] {
63+
black_box(memchr::memmem::find(haystack.as_bytes(), needle.as_bytes()));
64+
}
65+
}
66+
});
67+
});
68+
5969
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6070
{
6171
use sliceslice::x86::DynamicAvx2Searcher;
@@ -136,6 +146,14 @@ fn search_haystack<M: Measurement>(
136146
});
137147
});
138148

149+
group.bench_function("memchr::memmem::find", |b| {
150+
b.iter(|| {
151+
for needle in &needles {
152+
black_box(memchr::memmem::find(haystack, needle.as_bytes()));
153+
}
154+
});
155+
});
156+
139157
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
140158
{
141159
use sliceslice::x86::DynamicAvx2Searcher;

bench/benches/random.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ fn search<M: Measurement>(c: &mut Criterion<M>) {
4949
},
5050
);
5151

52+
group.bench_with_input(
53+
BenchmarkId::new("memchr::memmem::find", parameter),
54+
&size,
55+
|b, _| {
56+
b.iter(|| black_box(memchr::memmem::find(haystack, needle)));
57+
},
58+
);
59+
5260
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5361
{
5462
use sliceslice::x86::DynamicAvx2Searcher;

0 commit comments

Comments
 (0)