Add benchmark for strncmp

Test: run benchmark
Change-Id: Id99d81fe4d2a72a7f22414c7eea3ef3d873022ab
This commit is contained in:
Haibo Huang 2018-08-21 12:55:37 -07:00
parent d1214b0c68
commit e466cc0d55
1 changed files with 19 additions and 0 deletions

View File

@ -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<char> s1;
std::vector<char> 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);