Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 17 | #include <stdint.h> |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 18 | #include <string.h> |
| 19 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 20 | #include <benchmark/benchmark.h> |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 21 | #include "util.h" |
Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 22 | |
Chih-Hung Hsieh | 1a5fd9c | 2016-06-10 11:07:21 -0700 | [diff] [blame] | 23 | constexpr auto KB = 1024; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 24 | |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 25 | // NOTE: these constants are temporary replacements for AT_COMMON_SIZES until |
| 26 | // the new interface for Bionic benchmarks is implemented. |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 27 | |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 28 | // Set all four to 0 to test normal alignment. |
| 29 | #define AT_SRC_ALIGN 0 |
| 30 | #define AT_DST_ALIGN 0 |
| 31 | |
| 32 | #define AT_ALIGNED_TWOBUF \ |
| 33 | Args({(8), AT_SRC_ALIGN, AT_DST_ALIGN})->Args({(64), AT_SRC_ALIGN, AT_DST_ALIGN})-> \ |
| 34 | Args({(512), AT_SRC_ALIGN, AT_DST_ALIGN})->Args({(1*KB), AT_SRC_ALIGN, AT_DST_ALIGN})-> \ |
| 35 | Args({(8*KB), AT_SRC_ALIGN, AT_DST_ALIGN})->Args({(16*KB), AT_SRC_ALIGN, AT_DST_ALIGN})-> \ |
| 36 | Args({(32*KB), AT_SRC_ALIGN, AT_DST_ALIGN})->Args({(64*KB), AT_SRC_ALIGN, AT_DST_ALIGN}) |
| 37 | |
| 38 | #define AT_ALIGNED_ONEBUF \ |
| 39 | Args({(8), AT_SRC_ALIGN})->Args({(64), AT_SRC_ALIGN})->Args({(512), AT_SRC_ALIGN})-> \ |
| 40 | Args({(1*KB), AT_SRC_ALIGN})->Args({(8*KB), AT_SRC_ALIGN})->Args({(16*KB), AT_SRC_ALIGN})-> \ |
| 41 | Args({(32*KB), AT_SRC_ALIGN})->Args({(64*KB), AT_SRC_ALIGN}) |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 43 | static void BM_string_memcmp(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 44 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 45 | const size_t src_alignment = state.range(1); |
| 46 | const size_t dst_alignment = state.range(2); |
| 47 | |
| 48 | std::vector<char> src; |
| 49 | std::vector<char> dst; |
| 50 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 51 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'x'); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 52 | |
| 53 | volatile int c __attribute__((unused)) = 0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 54 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 55 | c += memcmp(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 58 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 59 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 60 | BENCHMARK(BM_string_memcmp)->AT_ALIGNED_TWOBUF; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 61 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 62 | static void BM_string_memcpy(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 63 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 64 | const size_t src_alignment = state.range(1); |
| 65 | const size_t dst_alignment = state.range(2); |
| 66 | |
| 67 | std::vector<char> src; |
| 68 | std::vector<char> dst; |
| 69 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 70 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 71 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 72 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 73 | memcpy(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 76 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 77 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 78 | BENCHMARK(BM_string_memcpy)->AT_ALIGNED_TWOBUF; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 79 | |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 80 | static void BM_string_memmove_non_overlapping(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 81 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 82 | const size_t src_alignment = state.range(1); |
| 83 | const size_t dst_alignment = state.range(2); |
| 84 | |
| 85 | std::vector<char> src; |
| 86 | std::vector<char> dst; |
| 87 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 88 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'y'); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 89 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 90 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 91 | memmove(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 94 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 95 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 96 | BENCHMARK(BM_string_memmove_non_overlapping)->AT_ALIGNED_TWOBUF; |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 97 | |
| 98 | static void BM_string_memmove_overlap_dst_before_src(benchmark::State& state) { |
| 99 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 100 | const size_t alignment = state.range(1); |
| 101 | |
| 102 | std::vector<char> buf(3 * alignment + nbytes + 1, 'x'); |
| 103 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 104 | |
| 105 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 106 | memmove(buf_aligned, buf_aligned + 1, nbytes); // Worst-case overlap. |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 110 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 111 | BENCHMARK(BM_string_memmove_overlap_dst_before_src)->AT_ALIGNED_ONEBUF; |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 112 | |
| 113 | static void BM_string_memmove_overlap_src_before_dst(benchmark::State& state) { |
| 114 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 115 | const size_t alignment = state.range(1); |
| 116 | |
| 117 | std::vector<char> buf; |
| 118 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 119 | |
| 120 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 121 | memmove(buf_aligned + 1, buf_aligned, nbytes); // Worst-case overlap. |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 125 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 126 | BENCHMARK(BM_string_memmove_overlap_src_before_dst)->AT_ALIGNED_ONEBUF; |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 127 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 128 | static void BM_string_memset(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 129 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 130 | const size_t alignment = state.range(1); |
| 131 | |
| 132 | std::vector<char> buf; |
| 133 | char* buf_aligned = GetAlignedPtr(&buf, alignment, nbytes + 1); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 134 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 135 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 136 | memset(buf_aligned, 0, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 139 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 140 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 141 | BENCHMARK(BM_string_memset)->AT_ALIGNED_ONEBUF; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 142 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 143 | static void BM_string_strlen(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 144 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 145 | const size_t alignment = state.range(1); |
| 146 | |
| 147 | std::vector<char> buf; |
| 148 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
| 149 | buf_aligned[nbytes - 1] = '\0'; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 150 | |
| 151 | volatile int c __attribute__((unused)) = 0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 152 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 153 | c += strlen(buf_aligned); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 156 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 157 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 158 | BENCHMARK(BM_string_strlen)->AT_ALIGNED_ONEBUF; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 159 | |
| 160 | static void BM_string_strcat_copy_only(benchmark::State& state) { |
| 161 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 162 | const size_t src_alignment = state.range(1); |
| 163 | const size_t dst_alignment = state.range(2); |
| 164 | |
| 165 | std::vector<char> src; |
| 166 | std::vector<char> dst; |
| 167 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 168 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes + 2); |
| 169 | src_aligned[nbytes - 1] = '\0'; |
| 170 | dst_aligned[0] = 'y'; |
| 171 | dst_aligned[1] = 'y'; |
| 172 | dst_aligned[2] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 173 | |
| 174 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 175 | strcat(dst_aligned, src_aligned); |
| 176 | dst_aligned[2] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 180 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 181 | BENCHMARK(BM_string_strcat_copy_only)->AT_ALIGNED_TWOBUF; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 182 | |
| 183 | static void BM_string_strcat_seek_only(benchmark::State& state) { |
| 184 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 185 | const size_t src_alignment = state.range(1); |
| 186 | const size_t dst_alignment = state.range(2); |
| 187 | |
| 188 | std::vector<char> src; |
| 189 | std::vector<char> dst; |
| 190 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, 3, 'x'); |
| 191 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes + 2, 'y'); |
| 192 | src_aligned[2] = '\0'; |
| 193 | dst_aligned[nbytes - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 194 | |
| 195 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 196 | strcat(dst_aligned, src_aligned); |
| 197 | dst_aligned[nbytes - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 201 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 202 | BENCHMARK(BM_string_strcat_seek_only)->AT_ALIGNED_TWOBUF; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 203 | |
| 204 | static void BM_string_strcat_half_copy_half_seek(benchmark::State& state) { |
| 205 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 206 | const size_t src_alignment = state.range(1); |
| 207 | const size_t dst_alignment = state.range(2); |
| 208 | |
| 209 | std::vector<char> src; |
| 210 | std::vector<char> dst; |
| 211 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes / 2, 'x'); |
| 212 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'y'); |
| 213 | src_aligned[nbytes / 2 - 1] = '\0'; |
| 214 | dst_aligned[nbytes / 2 - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 215 | |
| 216 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 217 | strcat(dst_aligned, src_aligned); |
| 218 | dst_aligned[nbytes / 2 - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 222 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 223 | BENCHMARK(BM_string_strcat_half_copy_half_seek)->AT_ALIGNED_TWOBUF; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 224 | |
| 225 | static void BM_string_strcpy(benchmark::State& state) { |
| 226 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 227 | const size_t src_alignment = state.range(1); |
| 228 | const size_t dst_alignment = state.range(2); |
| 229 | |
| 230 | std::vector<char> src; |
| 231 | std::vector<char> dst; |
| 232 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 233 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes); |
| 234 | src_aligned[nbytes - 1] = '\0'; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 235 | |
| 236 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 237 | strcpy(dst_aligned, src_aligned); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 241 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 242 | BENCHMARK(BM_string_strcpy)->AT_ALIGNED_TWOBUF; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 243 | |
| 244 | static void BM_string_strcmp(benchmark::State& state) { |
| 245 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 246 | const size_t s1_alignment = state.range(1); |
| 247 | const size_t s2_alignment = state.range(2); |
| 248 | |
| 249 | std::vector<char> s1; |
| 250 | std::vector<char> s2; |
| 251 | char* s1_aligned = GetAlignedPtrFilled(&s1, s1_alignment, nbytes, 'x'); |
| 252 | char* s2_aligned = GetAlignedPtrFilled(&s2, s2_alignment, nbytes, 'x'); |
| 253 | s1_aligned[nbytes - 1] = '\0'; |
| 254 | s2_aligned[nbytes - 1] = '\0'; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 255 | |
| 256 | volatile int c __attribute__((unused)); |
| 257 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 258 | c = strcmp(s1_aligned, s2_aligned); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 262 | } |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 263 | BENCHMARK(BM_string_strcmp)->AT_ALIGNED_TWOBUF; |