Add trivial towlower/towupper benchmarks.
Currently 11ns for both ascii and unicode in 64-bit, 15ns for 32-bit.
Test: ran benchmarks
Change-Id: Ie810b324c855b52b66a96889a194bc5b5b55653f
diff --git a/benchmarks/Android.bp b/benchmarks/Android.bp
index 370e040..f2ab32a 100644
--- a/benchmarks/Android.bp
+++ b/benchmarks/Android.bp
@@ -40,6 +40,7 @@
"string_benchmark.cpp",
"time_benchmark.cpp",
"unistd_benchmark.cpp",
+ "wctype_benchmark.cpp",
],
shared_libs: ["liblog"],
static_libs: [
diff --git a/benchmarks/wctype_benchmark.cpp b/benchmarks/wctype_benchmark.cpp
new file mode 100644
index 0000000..f030ddc
--- /dev/null
+++ b/benchmarks/wctype_benchmark.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2019 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 <wctype.h>
+
+#include <benchmark/benchmark.h>
+#include "util.h"
+
+static void BM_wctype_towlower_ascii_y(benchmark::State& state) {
+ for (auto _ : state) {
+ towlower('X');
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_ascii_y);
+
+static void BM_wctype_towlower_ascii_n(benchmark::State& state) {
+ for (auto _ : state) {
+ towlower('x');
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_ascii_n);
+
+static void BM_wctype_towlower_unicode_y(benchmark::State& state) {
+ for (auto _ : state) {
+ towlower(0x0391);
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_unicode_y);
+
+static void BM_wctype_towlower_unicode_n(benchmark::State& state) {
+ for (auto _ : state) {
+ towlower(0x03b1);
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_unicode_n);
+
+static void BM_wctype_towupper_ascii_y(benchmark::State& state) {
+ for (auto _ : state) {
+ towupper('x');
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_ascii_y);
+
+static void BM_wctype_towupper_ascii_n(benchmark::State& state) {
+ for (auto _ : state) {
+ towupper('X');
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_ascii_n);
+
+static void BM_wctype_towupper_unicode_y(benchmark::State& state) {
+ for (auto _ : state) {
+ towupper(0x03b1);
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_unicode_y);
+
+static void BM_wctype_towupper_unicode_n(benchmark::State& state) {
+ for (auto _ : state) {
+ towupper(0x0391);
+ }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_unicode_n);