From e466cc0d5548472e6e78c9994e3c2c982157b549 Mon Sep 17 00:00:00 2001 From: Haibo Huang Date: Tue, 21 Aug 2018 12:55:37 -0700 Subject: [PATCH] Add benchmark for strncmp Test: run benchmark Change-Id: Id99d81fe4d2a72a7f22414c7eea3ef3d873022ab --- benchmarks/string_benchmark.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp index 38122f2ed..d1766758c 100644 --- a/benchmarks/string_benchmark.cpp +++ b/benchmarks/string_benchmark.cpp @@ -248,6 +248,25 @@ static void BM_string_strcmp(benchmark::State& state) { } BIONIC_BENCHMARK_WITH_ARG(BM_string_strcmp, "AT_ALIGNED_TWOBUF"); +static void BM_string_strncmp(benchmark::State& state) { + const size_t nbytes = state.range(0); + const size_t s1_alignment = state.range(1); + const size_t s2_alignment = state.range(2); + + std::vector s1; + std::vector s2; + char* s1_aligned = GetAlignedPtrFilled(&s1, s1_alignment, nbytes, 'x'); + char* s2_aligned = GetAlignedPtrFilled(&s2, s2_alignment, nbytes, 'x'); + + volatile int c __attribute__((unused)); + for (auto _ : state) { + c = strncmp(s1_aligned, s2_aligned, nbytes); + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BIONIC_BENCHMARK_WITH_ARG(BM_string_strncmp, "AT_ALIGNED_TWOBUF"); + static void BM_string_strstr(benchmark::State& state) { const size_t nbytes = state.range(0); const size_t haystack_alignment = state.range(1);