summaryrefslogtreecommitdiff
path: root/benchmarks/string_benchmark.cpp
diff options
context:
space:
mode:
authorAnders Lewis <agloo@google.com>2017-08-08 18:29:51 -0700
committerAnders Lewis <agloo@google.com>2017-08-09 15:26:37 -0700
commitac4f4b43a3d19f40fc1138c5f78a3d5afd535935 (patch)
tree383382ddc413b182c7b84cab5c2e47004bfd9470 /benchmarks/string_benchmark.cpp
parenta7b0f8899790198cd9e72950f481679fe31e1a92 (diff)
Add musl benchmarks.
Test: Unit tests. Change-Id: Ifb2911825f84b95fe64a803bfabd32fb81210eae
Diffstat (limited to 'benchmarks/string_benchmark.cpp')
-rw-r--r--benchmarks/string_benchmark.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp
index 729b20dbd..94e7583f6 100644
--- a/benchmarks/string_benchmark.cpp
+++ b/benchmarks/string_benchmark.cpp
@@ -241,3 +241,49 @@ static void BM_string_strcmp(benchmark::State& state) {
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
BIONIC_BENCHMARK(BM_string_strcmp);
+
+static void BM_string_strstr(benchmark::State& state) {
+ const size_t nbytes = state.range(0);
+ const size_t haystack_alignment = state.range(1);
+ const size_t needle_alignment = state.range(2);
+
+ std::vector<char> haystack;
+ std::vector<char> needle;
+ char* haystack_aligned = GetAlignedPtrFilled(&haystack, haystack_alignment, nbytes, 'x');
+ char* needle_aligned = GetAlignedPtrFilled(&needle, needle_alignment,
+ std::min(nbytes, static_cast<size_t>(5)), 'x');
+
+ if (nbytes / 4 > 2) {
+ for (size_t i = 0; nbytes / 4 >= 2 && i < nbytes / 4 - 2; i++) {
+ haystack_aligned[4 * i + 3] = 'y';
+ }
+ }
+ haystack_aligned[nbytes - 1] = '\0';
+ needle_aligned[needle.size() - 1] = '\0';
+
+ while (state.KeepRunning()) {
+ if (strstr(haystack_aligned, needle_aligned) == nullptr) {
+ abort();
+ }
+ }
+
+ state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
+}
+BIONIC_BENCHMARK(BM_string_strstr);
+
+static void BM_string_strchr(benchmark::State& state) {
+ const size_t nbytes = state.range(0);
+ const size_t haystack_alignment = state.range(1);
+
+ std::vector<char> haystack;
+ char* haystack_aligned = GetAlignedPtrFilled(&haystack, haystack_alignment, nbytes, 'x');
+
+ while (state.KeepRunning()) {
+ if (strchr(haystack_aligned, 'y') != nullptr) {
+ abort();
+ }
+ }
+
+ state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
+}
+BIONIC_BENCHMARK(BM_string_strchr);