diff options
author | Christopher Ferris <cferris@google.com> | 2017-06-16 16:40:01 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-06-16 16:40:03 +0000 |
commit | f0ee60a434675a2923c9c6968c8d5206ca6a6834 (patch) | |
tree | 29dd414205a44b07278523030251ee28f7a1d133 /benchmarks/string_benchmark.cpp | |
parent | ae837f2e5936d621a3d3760a464aed83f2cd337e (diff) | |
parent | 1c487e103618b7e4e3480f59375761e94ce80d2a (diff) |
Merge "Add benchmarks for strcpy and strcmp."
Diffstat (limited to 'benchmarks/string_benchmark.cpp')
-rw-r--r-- | benchmarks/string_benchmark.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp index e6c65703e..86a7c359f 100644 --- a/benchmarks/string_benchmark.cpp +++ b/benchmarks/string_benchmark.cpp @@ -173,3 +173,33 @@ static void BM_string_strcat_half_copy_half_seek(benchmark::State& state) { state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); } BENCHMARK(BM_string_strcat_half_copy_half_seek)->AT_COMMON_SIZES; + +static void BM_string_strcpy(benchmark::State& state) { + const size_t nbytes = state.range(0); + std::vector<char> src(nbytes, 'x'); + std::vector<char> dst(nbytes); + src[nbytes - 1] = '\0'; + + while (state.KeepRunning()) { + strcpy(dst.data(), src.data()); + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BENCHMARK(BM_string_strcpy)->AT_COMMON_SIZES; + +static void BM_string_strcmp(benchmark::State& state) { + const size_t nbytes = state.range(0); + std::vector<char> s1(nbytes, 'x'); + std::vector<char> s2(nbytes, 'x'); + s1[nbytes - 1] = '\0'; + s2[nbytes - 1] = '\0'; + + volatile int c __attribute__((unused)); + while (state.KeepRunning()) { + c = strcmp(s1.data(), s2.data()); + } + + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} +BENCHMARK(BM_string_strcmp)->AT_COMMON_SIZES; |