aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-09-20 15:03:49 -0700
committerChristopher Ferris <cferris@google.com>2018-09-20 15:03:49 -0700
commit4fae703029a75d7f8b649d1f4609ba8926c653e3 (patch)
treea335dd49f8753a95bd53b16e455a87c4278dc388 /benchmarks
parent8d11bea6c57cf62171f4157e0f2061ada4c19b10 (diff)
downloadandroid_bionic-4fae703029a75d7f8b649d1f4609ba8926c653e3.tar.gz
android_bionic-4fae703029a75d7f8b649d1f4609ba8926c653e3.tar.bz2
android_bionic-4fae703029a75d7f8b649d1f4609ba8926c653e3.zip
Touch the memory when doing malloc/free benchmark.
Also, update the benchmark loop for modern C++. Test: Ran benchmarks. Change-Id: I925446b893793eb8c2c6759716cdd3dbbcf1e7c1
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/stdlib_benchmark.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/benchmarks/stdlib_benchmark.cpp b/benchmarks/stdlib_benchmark.cpp
index 880bc1d3e..7330dc423 100644
--- a/benchmarks/stdlib_benchmark.cpp
+++ b/benchmarks/stdlib_benchmark.cpp
@@ -18,17 +18,24 @@
#include <langinfo.h>
#include <locale.h>
#include <stdlib.h>
+#include <unistd.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);
+ int pagesize = getpagesize();
+
+ void* ptr;
+ for (auto _ : state) {
+ ptr = malloc(nbytes);
+ // Make the entire allocation resident.
+ uint8_t* data = reinterpret_cast<uint8_t*>(ptr);
+ for (size_t i = 0; i < nbytes; i += pagesize) {
+ data[i] = 1;
+ }
+ free(ptr);
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
@@ -70,7 +77,7 @@ static void BM_stdlib_mbstowcs(benchmark::State& state) {
buf[l++] = 0;
volatile size_t c __attribute__((unused)) = 0;
- while (state.KeepRunning()) {
+ for (auto _ : state) {
c = mbstowcs(widebuf_aligned, buf_aligned, 500000);
}
@@ -110,7 +117,7 @@ static void BM_stdlib_mbrtowc(benchmark::State& state) {
buf[l++] = 0;
wchar_t wc = 0;
- while (state.KeepRunning()) {
+ for (auto _ : state) {
for (j = 0; buf_aligned[j]; j+=mbrtowc(&wc, buf_aligned + j, 4, nullptr)) {
}
}
@@ -120,42 +127,42 @@ static void BM_stdlib_mbrtowc(benchmark::State& state) {
BIONIC_BENCHMARK_WITH_ARG(BM_stdlib_mbrtowc, "0");
void BM_stdlib_atoi(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(atoi(" -123"));
}
}
BIONIC_BENCHMARK(BM_stdlib_atoi);
void BM_stdlib_atol(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(atol(" -123"));
}
}
BIONIC_BENCHMARK(BM_stdlib_atol);
void BM_stdlib_strtol(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(strtol(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtol);
void BM_stdlib_strtoll(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(strtoll(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtoll);
void BM_stdlib_strtoul(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(strtoul(" -123", nullptr, 0));
}
}
BIONIC_BENCHMARK(BM_stdlib_strtoul);
void BM_stdlib_strtoull(benchmark::State& state) {
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(strtoull(" -123", nullptr, 0));
}
}