aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-12-19 20:23:39 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-12-19 20:23:39 +0000
commit811a1dd8680ccc0c052651cb30ecf6416613c627 (patch)
tree93dd4a04aa83621c23e4fb953fb421134fa1a97d /benchmarks
parentba69b37a75a793a5c534c6e53d2958770fa54786 (diff)
parent7063a838be5eb1f28f40a554944a31bab49c3211 (diff)
downloadandroid_bionic-811a1dd8680ccc0c052651cb30ecf6416613c627.tar.gz
android_bionic-811a1dd8680ccc0c052651cb30ecf6416613c627.tar.bz2
android_bionic-811a1dd8680ccc0c052651cb30ecf6416613c627.zip
Merge "More benchmarks."
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/Android.bp2
-rw-r--r--benchmarks/inttypes_benchmark.cpp34
-rw-r--r--benchmarks/stdio_benchmark.cpp69
-rw-r--r--benchmarks/stdlib_benchmark.cpp42
4 files changed, 147 insertions, 0 deletions
diff --git a/benchmarks/Android.bp b/benchmarks/Android.bp
index be61eda4c..115236bf6 100644
--- a/benchmarks/Android.bp
+++ b/benchmarks/Android.bp
@@ -22,11 +22,13 @@ cc_defaults {
"-Wall",
"-Wextra",
"-Werror",
+ "-Wno-gcc-compat",
"-Wunused",
],
srcs: [
"bionic_benchmarks.cpp",
"atomic_benchmark.cpp",
+ "inttypes_benchmark.cpp",
"math_benchmark.cpp",
"property_benchmark.cpp",
"pthread_benchmark.cpp",
diff --git a/benchmarks/inttypes_benchmark.cpp b/benchmarks/inttypes_benchmark.cpp
new file mode 100644
index 000000000..f123eb8e9
--- /dev/null
+++ b/benchmarks/inttypes_benchmark.cpp
@@ -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);
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
index 872725d34..965a3ae9f 100644
--- a/benchmarks/stdio_benchmark.cpp
+++ b/benchmarks/stdio_benchmark.cpp
@@ -223,6 +223,7 @@ static void BM_stdio_scanf_d(benchmark::State& state) {
}
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) {
while (state.KeepRunning()) {
uintptr_t start;
@@ -236,3 +237,71 @@ static void BM_stdio_scanf_maps(benchmark::State& state) {
}
}
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);
diff --git a/benchmarks/stdlib_benchmark.cpp b/benchmarks/stdlib_benchmark.cpp
index 0bee683e4..24773dea9 100644
--- a/benchmarks/stdlib_benchmark.cpp
+++ b/benchmarks/stdlib_benchmark.cpp
@@ -118,3 +118,45 @@ static void BM_stdlib_mbrtowc(benchmark::State& state) {
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(500000));
}
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);