diff options
author | Christopher Ferris <cferris@google.com> | 2017-08-10 23:44:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-10 23:44:04 +0000 |
commit | 73c3be22199a42bed53245b9b648e276de0b6422 (patch) | |
tree | 6c592e09bd57616bd84d32efce96645ee8a25094 /benchmarks/string_benchmark.cpp | |
parent | cf764c05e43921e4d3f927a5eaca1c6ecafe046b (diff) | |
parent | ac4f4b43a3d19f40fc1138c5f78a3d5afd535935 (diff) | |
download | android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.gz android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.bz2 android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.zip |
Merge "Add musl benchmarks."
Diffstat (limited to 'benchmarks/string_benchmark.cpp')
-rw-r--r-- | benchmarks/string_benchmark.cpp | 46 |
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); |