From 271be9bb7df6f3910a929ef7bff55fbd9bc2dee6 Mon Sep 17 00:00:00 2001 From: Anders Lewis Date: Wed, 7 Jun 2017 13:00:38 -0700 Subject: Split memmove benchmark into separate overlapping (src before dst and dst before src) and non-overlapping tests. Test: Ran benchmarks and verified that runtimes were sensible. Change-Id: Ia7fbc5596dfdc162fff2364f4ef6dafe5549b907 --- benchmarks/string_benchmark.cpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'benchmarks/string_benchmark.cpp') diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp index 41306db1c..aa1e8c9aa 100644 --- a/benchmarks/string_benchmark.cpp +++ b/benchmarks/string_benchmark.cpp @@ -58,19 +58,42 @@ static void BM_string_memcpy(benchmark::State& state) { } BENCHMARK(BM_string_memcpy)->AT_COMMON_SIZES; -static void BM_string_memmove(benchmark::State& state) { +static void BM_string_memmove_non_overlapping(benchmark::State& state) { const size_t nbytes = state.range(0); - char* buf = new char[nbytes + 64]; - memset(buf, 'x', nbytes + 64); + std::vector src(nbytes, 'x'); + std::vector dst(nbytes, 'x'); while (state.KeepRunning()) { - memmove(buf, buf + 1, nbytes); // Worst-case overlap. + memmove(dst.data(), src.data(), nbytes); } state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); - delete[] buf; } -BENCHMARK(BM_string_memmove)->AT_COMMON_SIZES; +BENCHMARK(BM_string_memmove_non_overlapping)->AT_COMMON_SIZES; + +static void BM_string_memmove_overlap_dst_before_src(benchmark::State& state) { + const size_t nbytes = state.range(0); + std::vector buf(nbytes + 1, 'x'); + + while (state.KeepRunning()) { + memmove(buf.data(), buf.data() + 1, nbytes); // Worst-case overlap. + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BENCHMARK(BM_string_memmove_overlap_dst_before_src)->AT_COMMON_SIZES; + +static void BM_string_memmove_overlap_src_before_dst(benchmark::State& state) { + const size_t nbytes = state.range(0); + std::vector buf(nbytes + 1, 'x'); + + while (state.KeepRunning()) { + memmove(buf.data() + 1, buf.data(), nbytes); // Worst-case overlap. + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BENCHMARK(BM_string_memmove_overlap_src_before_dst)->AT_COMMON_SIZES; static void BM_string_memset(benchmark::State& state) { const size_t nbytes = state.range(0); -- cgit v1.2.3