summaryrefslogtreecommitdiff
path: root/benchmarks/string_benchmark.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-10-22 13:43:59 -0700
committerElliott Hughes <enh@google.com>2020-10-22 13:43:59 -0700
commite8693e78711e8f45ccd2b610e4dbe0b94d551cc9 (patch)
tree5b7a67244a6a122e27fca20f84d0a4f78d487fe2 /benchmarks/string_benchmark.cpp
parent9aa6b15d799ac246e842552fca555920a93ce46b (diff)
Make more use of benchmark::DoNotOptimize in benchmarks.
A lot of these benchmarks predate DoNotOptimize and rolled their own hacks. Bug: http://b/148307629 Test: ran benchmarks before & after and got similar results Change-Id: If44699d261b687f6253af709edda58f4c90fb285
Diffstat (limited to 'benchmarks/string_benchmark.cpp')
-rw-r--r--benchmarks/string_benchmark.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp
index d1766758c..9be54c7b5 100644
--- a/benchmarks/string_benchmark.cpp
+++ b/benchmarks/string_benchmark.cpp
@@ -31,9 +31,8 @@ static void BM_string_memcmp(benchmark::State& state) {
char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x');
char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'x');
- volatile int c __attribute__((unused)) = 0;
while (state.KeepRunning()) {
- c += memcmp(dst_aligned, src_aligned, nbytes);
+ benchmark::DoNotOptimize(memcmp(dst_aligned, src_aligned, nbytes));
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
@@ -129,9 +128,8 @@ static void BM_string_strlen(benchmark::State& state) {
char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x');
buf_aligned[nbytes - 1] = '\0';
- volatile int c __attribute__((unused)) = 0;
while (state.KeepRunning()) {
- c += strlen(buf_aligned);
+ benchmark::DoNotOptimize(strlen(buf_aligned));
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
@@ -239,9 +237,8 @@ static void BM_string_strcmp(benchmark::State& state) {
s1_aligned[nbytes - 1] = '\0';
s2_aligned[nbytes - 1] = '\0';
- volatile int c __attribute__((unused));
while (state.KeepRunning()) {
- c = strcmp(s1_aligned, s2_aligned);
+ benchmark::DoNotOptimize(strcmp(s1_aligned, s2_aligned));
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
@@ -258,9 +255,8 @@ static void BM_string_strncmp(benchmark::State& state) {
char* s1_aligned = GetAlignedPtrFilled(&s1, s1_alignment, nbytes, 'x');
char* s2_aligned = GetAlignedPtrFilled(&s2, s2_alignment, nbytes, 'x');
- volatile int c __attribute__((unused));
for (auto _ : state) {
- c = strncmp(s1_aligned, s2_aligned, nbytes);
+ benchmark::DoNotOptimize(strncmp(s1_aligned, s2_aligned, nbytes));
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));