Merge "More benchmarks."

This commit is contained in:
Elliott Hughes 2017-12-19 20:23:39 +00:00 committed by Gerrit Code Review
commit 811a1dd868
4 changed files with 147 additions and 0 deletions

View file

@ -22,11 +22,13 @@ cc_defaults {
"-Wall", "-Wall",
"-Wextra", "-Wextra",
"-Werror", "-Werror",
"-Wno-gcc-compat",
"-Wunused", "-Wunused",
], ],
srcs: [ srcs: [
"bionic_benchmarks.cpp", "bionic_benchmarks.cpp",
"atomic_benchmark.cpp", "atomic_benchmark.cpp",
"inttypes_benchmark.cpp",
"math_benchmark.cpp", "math_benchmark.cpp",
"property_benchmark.cpp", "property_benchmark.cpp",
"pthread_benchmark.cpp", "pthread_benchmark.cpp",

View file

@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <inttypes.h>
#include <benchmark/benchmark.h>
#include "util.h"
void BM_inttypes_strtoimax(benchmark::State& state) {
while (state.KeepRunning()) {
strtoimax(" -123", nullptr, 0);
}
}
BIONIC_BENCHMARK(BM_inttypes_strtoimax);
void BM_inttypes_strtoumax(benchmark::State& state) {
while (state.KeepRunning()) {
strtoumax(" -123", nullptr, 0);
}
}
BIONIC_BENCHMARK(BM_inttypes_strtoumax);

View file

@ -223,6 +223,7 @@ static void BM_stdio_scanf_d(benchmark::State& state) {
} }
BIONIC_BENCHMARK(BM_stdio_scanf_d); BIONIC_BENCHMARK(BM_stdio_scanf_d);
// Parsing maps is a common use of sscanf with a relatively complex format string.
static void BM_stdio_scanf_maps(benchmark::State& state) { static void BM_stdio_scanf_maps(benchmark::State& state) {
while (state.KeepRunning()) { while (state.KeepRunning()) {
uintptr_t start; uintptr_t start;
@ -236,3 +237,71 @@ static void BM_stdio_scanf_maps(benchmark::State& state) {
} }
} }
BIONIC_BENCHMARK(BM_stdio_scanf_maps); BIONIC_BENCHMARK(BM_stdio_scanf_maps);
// Hard-coded equivalent of the maps sscanf from libunwindstack/Maps.cpp for a baseline.
static int ParseMap(const char* line, const char* /*fmt*/, uintptr_t* start, uintptr_t* end,
char* permissions, uintptr_t* offset, int* name_pos) __attribute__((noinline)) {
char* str;
const char* old_str = line;
// "%" PRIxPTR "-"
*start = strtoul(old_str, &str, 16);
if (old_str == str || *str++ != '-') return 0;
// "%" PRIxPTR " "
old_str = str;
*end = strtoul(old_str, &str, 16);
if (old_str == str || !std::isspace(*str++)) return 0;
while (std::isspace(*str)) str++;
// "%4s "
if (*str == '\0') return 0;
permissions[0] = *str;
str++;
permissions[1] = *str;
str++;
permissions[2] = *str;
str++;
permissions[3] = *str;
str++;
permissions[4] = 0;
if (!std::isspace(*str++)) return 0;
// "%" PRIxPTR " "
old_str = str;
*offset = strtoul(old_str, &str, 16);
if (old_str == str || !std::isspace(*str)) return 0;
// "%*x:%*x "
old_str = str;
(void)strtoul(old_str, &str, 16);
if (old_str == str || *str++ != ':') return 0;
if (std::isspace(*str)) return 0;
old_str = str;
(void)strtoul(str, &str, 16);
if (old_str == str || !std::isspace(*str++)) return 0;
// "%*d "
old_str = str;
(void)strtoul(old_str, &str, 10);
if (old_str == str || (!std::isspace(*str) && *str != '\0')) return 0;
while (std::isspace(*str)) str++;
// "%n"
*name_pos = (str - line);
return 4;
}
static void BM_stdio_scanf_maps_baseline(benchmark::State& state) {
while (state.KeepRunning()) {
uintptr_t start;
uintptr_t end;
uintptr_t offset;
char permissions[5];
int name_pos;
if (ParseMap("6f000000-6f01e000 rwxp 00000000 00:0c 16389419 /system/lib/libcomposer.so",
"%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d %n",
&start, &end, permissions, &offset, &name_pos) != 4) abort();
}
}
BIONIC_BENCHMARK(BM_stdio_scanf_maps_baseline);

View file

@ -118,3 +118,45 @@ static void BM_stdlib_mbrtowc(benchmark::State& state) {
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(500000)); state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(500000));
} }
BIONIC_BENCHMARK_WITH_ARG(BM_stdlib_mbrtowc, "0"); BIONIC_BENCHMARK_WITH_ARG(BM_stdlib_mbrtowc, "0");
void BM_stdlib_atoi(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(atoi(" -123"));
}
}
BIONIC_BENCHMARK(BM_stdlib_atoi);
void BM_stdlib_atol(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(atol(" -123"));
}
}
BIONIC_BENCHMARK(BM_stdlib_atol);
void BM_stdlib_strtol(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(strtol(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtol);
void BM_stdlib_strtoll(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(strtoll(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtoll);
void BM_stdlib_strtoul(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(strtoul(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtoul);
void BM_stdlib_strtoull(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(strtoull(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtoull);