diff options
author | Elliott Hughes <enh@google.com> | 2016-02-17 10:23:52 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-03-07 13:50:50 -0800 |
commit | 281e06ba69ce6f591697acf65a24651050809920 (patch) | |
tree | c2a4caf009b63e8be398ef3da1f0e792f41c9746 /benchmarks/string_benchmark.cpp | |
parent | 925bf56447cf87da910441f12b302051e07549ba (diff) |
Switch bionic over to google-benchmark.
Also removes the old benchmarking library.
Change-Id: I4791ae69fa5dea03644d3d411c60b7c6d1fceae3
Diffstat (limited to 'benchmarks/string_benchmark.cpp')
-rw-r--r-- | benchmarks/string_benchmark.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp index 866aa0047..c04409d5d 100644 --- a/benchmarks/string_benchmark.cpp +++ b/benchmarks/string_benchmark.cpp @@ -17,7 +17,7 @@ #include <stdint.h> #include <string.h> -#include <benchmark/Benchmark.h> +#include <benchmark/benchmark.h> #define KB 1024 #define MB 1024*KB @@ -27,87 +27,77 @@ // TODO: test unaligned operation too? (currently everything will be 8-byte aligned by malloc.) -BENCHMARK_WITH_ARG(BM_string_memcmp, int)->AT_COMMON_SIZES; -void BM_string_memcmp::Run(int iters, int nbytes) { - StopBenchmarkTiming(); +static void BM_string_memcmp(benchmark::State& state) { + const size_t nbytes = state.range_x(); char* src = new char[nbytes]; char* dst = new char[nbytes]; memset(src, 'x', nbytes); memset(dst, 'x', nbytes); - StartBenchmarkTiming(); volatile int c __attribute__((unused)) = 0; - for (int i = 0; i < iters; ++i) { + while (state.KeepRunning()) { c += memcmp(dst, src, nbytes); } - StopBenchmarkTiming(); - SetBenchmarkBytesProcessed(uint64_t(iters) * uint64_t(nbytes)); + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); delete[] src; delete[] dst; } +BENCHMARK(BM_string_memcmp)->AT_COMMON_SIZES; -BENCHMARK_WITH_ARG(BM_string_memcpy, int)->AT_COMMON_SIZES; -void BM_string_memcpy::Run(int iters, int nbytes) { - StopBenchmarkTiming(); +static void BM_string_memcpy(benchmark::State& state) { + const size_t nbytes = state.range_x(); char* src = new char[nbytes]; char* dst = new char[nbytes]; memset(src, 'x', nbytes); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (state.KeepRunning()) { memcpy(dst, src, nbytes); } - StopBenchmarkTiming(); - SetBenchmarkBytesProcessed(uint64_t(iters) * uint64_t(nbytes)); + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); delete[] src; delete[] dst; } +BENCHMARK(BM_string_memcpy)->AT_COMMON_SIZES; -BENCHMARK_WITH_ARG(BM_string_memmove, int)->AT_COMMON_SIZES; -void BM_string_memmove::Run(int iters, int nbytes) { - StopBenchmarkTiming(); +static void BM_string_memmove(benchmark::State& state) { + const size_t nbytes = state.range_x(); char* buf = new char[nbytes + 64]; memset(buf, 'x', nbytes + 64); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (state.KeepRunning()) { memmove(buf, buf + 1, nbytes); // Worst-case overlap. } - StopBenchmarkTiming(); - SetBenchmarkBytesProcessed(uint64_t(iters) * uint64_t(nbytes)); + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); delete[] buf; } +BENCHMARK(BM_string_memmove)->AT_COMMON_SIZES; -BENCHMARK_WITH_ARG(BM_string_memset, int)->AT_COMMON_SIZES; -void BM_string_memset::Run(int iters, int nbytes) { - StopBenchmarkTiming(); +static void BM_string_memset(benchmark::State& state) { + const size_t nbytes = state.range_x(); char* dst = new char[nbytes]; - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (state.KeepRunning()) { memset(dst, 0, nbytes); } - StopBenchmarkTiming(); - SetBenchmarkBytesProcessed(uint64_t(iters) * uint64_t(nbytes)); + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); delete[] dst; } +BENCHMARK(BM_string_memset)->AT_COMMON_SIZES; -BENCHMARK_WITH_ARG(BM_string_strlen, int)->AT_COMMON_SIZES; -void BM_string_strlen::Run(int iters, int nbytes) { - StopBenchmarkTiming(); +static void BM_string_strlen(benchmark::State& state) { + const size_t nbytes = state.range_x(); char* s = new char[nbytes]; memset(s, 'x', nbytes); s[nbytes - 1] = 0; - StartBenchmarkTiming(); volatile int c __attribute__((unused)) = 0; - for (int i = 0; i < iters; ++i) { + while (state.KeepRunning()) { c += strlen(s); } - StopBenchmarkTiming(); - SetBenchmarkBytesProcessed(uint64_t(iters) * uint64_t(nbytes)); + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); delete[] s; } +BENCHMARK(BM_string_strlen)->AT_COMMON_SIZES; |