diff options
author | Christopher Ferris <cferris@google.com> | 2017-08-10 23:44:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-10 23:44:04 +0000 |
commit | 73c3be22199a42bed53245b9b648e276de0b6422 (patch) | |
tree | 6c592e09bd57616bd84d32efce96645ee8a25094 /benchmarks/stdlib_benchmark.cpp | |
parent | cf764c05e43921e4d3f927a5eaca1c6ecafe046b (diff) | |
parent | ac4f4b43a3d19f40fc1138c5f78a3d5afd535935 (diff) | |
download | android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.gz android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.bz2 android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.zip |
Merge "Add musl benchmarks."
Diffstat (limited to 'benchmarks/stdlib_benchmark.cpp')
-rw-r--r-- | benchmarks/stdlib_benchmark.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/benchmarks/stdlib_benchmark.cpp b/benchmarks/stdlib_benchmark.cpp new file mode 100644 index 000000000..7a12eb6eb --- /dev/null +++ b/benchmarks/stdlib_benchmark.cpp @@ -0,0 +1,115 @@ +/* + * 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 <langinfo.h> +#include <locale.h> +#include <stdlib.h> + +#include <benchmark/benchmark.h> +#include "util.h" + +static void BM_stdlib_malloc_free(benchmark::State& state) { + const size_t nbytes = state.range(0); + + void* c; + while (state.KeepRunning()) { + c = malloc(nbytes); + free(c); + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BIONIC_BENCHMARK(BM_stdlib_malloc_free); + +static void BM_stdlib_mbstowcs(benchmark::State& state) { + const size_t buf_alignment = state.range(0); + const size_t widebuf_alignment = state.range(1); + + std::vector<char> buf; + std::vector<wchar_t> widebuf; + + setlocale(LC_CTYPE, "C.UTF-8") + || setlocale(LC_CTYPE, "en_US.UTF-8") + || setlocale(LC_CTYPE, "en_GB.UTF-8") + || setlocale(LC_CTYPE, "en.UTF-8") + || setlocale(LC_CTYPE, "de_DE-8") + || setlocale(LC_CTYPE, "fr_FR-8"); + if (strcmp(nl_langinfo(CODESET), "UTF-8")) abort(); + + char* buf_aligned = GetAlignedPtr(&buf, buf_alignment, 500000); + wchar_t* widebuf_aligned = GetAlignedPtr(&widebuf, widebuf_alignment, 500000); + size_t i, j, k, l; + l = 0; + for (i=0xc3; i<0xe0; i++) + for (j=0x80; j<0xc0; j++) + buf[l++] = i, buf[l++] = j; + for (i=0xe1; i<0xed; i++) + for (j=0x80; j<0xc0; j++) + for (k=0x80; k<0xc0; k++) + buf[l++] = i, buf[l++] = j, buf[l++] = k; + for (i=0xf1; i<0xf4; i++) + for (j=0x80; j<0xc0; j++) + for (k=0x80; k<0xc0; k++) + buf[l++] = i, buf[l++] = j, buf[l++] = 0x80, buf[l++] = k; + buf[l++] = 0; + + volatile size_t c __attribute__((unused)) = 0; + while (state.KeepRunning()) { + c = mbstowcs(widebuf_aligned, buf_aligned, 500000); + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(500000)); +} +BIONIC_BENCHMARK(BM_stdlib_mbstowcs); + +static void BM_stdlib_mbrtowc(benchmark::State& state) { + const size_t buf_alignment = state.range(0); + + std::vector<char> buf; + + setlocale(LC_CTYPE, "C.UTF-8") + || setlocale(LC_CTYPE, "en_US.UTF-8") + || setlocale(LC_CTYPE, "en_GB.UTF-8") + || setlocale(LC_CTYPE, "en.UTF-8") + || setlocale(LC_CTYPE, "de_DE-8") + || setlocale(LC_CTYPE, "fr_FR-8"); + if (strcmp(nl_langinfo(CODESET), "UTF-8")) abort(); + + char* buf_aligned = GetAlignedPtr(&buf, buf_alignment, 500000); + size_t i, j, k, l; + l = 0; + for (i=0xc3; i<0xe0; i++) + for (j=0x80; j<0xc0; j++) + buf[l++] = i, buf[l++] = j; + for (i=0xe1; i<0xed; i++) + for (j=0x80; j<0xc0; j++) + for (k=0x80; k<0xc0; k++) + buf[l++] = i, buf[l++] = j, buf[l++] = k; + for (i=0xf1; i<0xf4; i++) + for (j=0x80; j<0xc0; j++) + for (k=0x80; k<0xc0; k++) + buf[l++] = i, buf[l++] = j, buf[l++] = 0x80, buf[l++] = k; + buf[l++] = 0; + + wchar_t wc = 0; + while (state.KeepRunning()) { + for (j = 0; buf_aligned[j]; j+=mbrtowc(&wc, buf_aligned + j, 4, NULL)) { + } + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(500000)); +} +BIONIC_BENCHMARK(BM_stdlib_mbrtowc); |