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 | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 21 | #include <util.h> |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 22 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 23 | static void BM_string_memcmp(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 24 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 25 | const size_t src_alignment = state.range(1); |
| 26 | const size_t dst_alignment = state.range(2); |
| 27 | |
| 28 | std::vector<char> src; |
| 29 | std::vector<char> dst; |
| 30 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 31 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'x'); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 32 | |
| 33 | volatile int c __attribute__((unused)) = 0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 34 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 35 | c += memcmp(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 38 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 39 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 40 | BIONIC_BENCHMARK(BM_string_memcmp); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 41 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 42 | static void BM_string_memcpy(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 43 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 44 | const size_t src_alignment = state.range(1); |
| 45 | const size_t dst_alignment = state.range(2); |
| 46 | |
| 47 | std::vector<char> src; |
| 48 | std::vector<char> dst; |
| 49 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 50 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 51 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 52 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 53 | memcpy(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 56 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 57 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 58 | BIONIC_BENCHMARK(BM_string_memcpy); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 59 | |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 60 | static void BM_string_memmove_non_overlapping(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 61 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 62 | const size_t src_alignment = state.range(1); |
| 63 | const size_t dst_alignment = state.range(2); |
| 64 | |
| 65 | std::vector<char> src; |
| 66 | std::vector<char> dst; |
| 67 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 68 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'y'); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 69 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 70 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 71 | memmove(dst_aligned, src_aligned, nbytes); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 74 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 75 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 76 | BIONIC_BENCHMARK(BM_string_memmove_non_overlapping); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 77 | |
| 78 | static void BM_string_memmove_overlap_dst_before_src(benchmark::State& state) { |
| 79 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 80 | const size_t alignment = state.range(1); |
| 81 | |
| 82 | std::vector<char> buf(3 * alignment + nbytes + 1, 'x'); |
| 83 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 84 | |
| 85 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 86 | memmove(buf_aligned, buf_aligned + 1, nbytes); // Worst-case overlap. |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 90 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 91 | BIONIC_BENCHMARK(BM_string_memmove_overlap_dst_before_src); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 92 | |
| 93 | static void BM_string_memmove_overlap_src_before_dst(benchmark::State& state) { |
| 94 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 95 | const size_t alignment = state.range(1); |
| 96 | |
| 97 | std::vector<char> buf; |
| 98 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 99 | |
| 100 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 101 | memmove(buf_aligned + 1, buf_aligned, nbytes); // Worst-case overlap. |
Anders Lewis | 271be9b | 2017-06-07 13:00:38 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 105 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 106 | BIONIC_BENCHMARK(BM_string_memmove_overlap_src_before_dst); |
Elliott Hughes | fbe44ec | 2012-11-09 14:59:21 -0800 | [diff] [blame] | 107 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 108 | static void BM_string_memset(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 109 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 110 | const size_t alignment = state.range(1); |
| 111 | |
| 112 | std::vector<char> buf; |
| 113 | char* buf_aligned = GetAlignedPtr(&buf, alignment, nbytes + 1); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 114 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 115 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 116 | memset(buf_aligned, 0, nbytes); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 119 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 120 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 121 | BIONIC_BENCHMARK(BM_string_memset); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 122 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 123 | static void BM_string_strlen(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 124 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 125 | const size_t alignment = state.range(1); |
| 126 | |
| 127 | std::vector<char> buf; |
| 128 | char* buf_aligned = GetAlignedPtrFilled(&buf, alignment, nbytes + 1, 'x'); |
| 129 | buf_aligned[nbytes - 1] = '\0'; |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 130 | |
| 131 | volatile int c __attribute__((unused)) = 0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 132 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 133 | c += strlen(buf_aligned); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 136 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
Elliott Hughes | 7be369d | 2012-11-08 15:37:43 -0800 | [diff] [blame] | 137 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 138 | BIONIC_BENCHMARK(BM_string_strlen); |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 139 | |
| 140 | static void BM_string_strcat_copy_only(benchmark::State& state) { |
| 141 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 142 | const size_t src_alignment = state.range(1); |
| 143 | const size_t dst_alignment = state.range(2); |
| 144 | |
| 145 | std::vector<char> src; |
| 146 | std::vector<char> dst; |
| 147 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 148 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes + 2); |
| 149 | src_aligned[nbytes - 1] = '\0'; |
| 150 | dst_aligned[0] = 'y'; |
| 151 | dst_aligned[1] = 'y'; |
| 152 | dst_aligned[2] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 153 | |
| 154 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 155 | strcat(dst_aligned, src_aligned); |
| 156 | dst_aligned[2] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 160 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 161 | BIONIC_BENCHMARK(BM_string_strcat_copy_only); |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 162 | |
| 163 | static void BM_string_strcat_seek_only(benchmark::State& state) { |
| 164 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 165 | const size_t src_alignment = state.range(1); |
| 166 | const size_t dst_alignment = state.range(2); |
| 167 | |
| 168 | std::vector<char> src; |
| 169 | std::vector<char> dst; |
| 170 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, 3, 'x'); |
| 171 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes + 2, 'y'); |
| 172 | src_aligned[2] = '\0'; |
| 173 | dst_aligned[nbytes - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 174 | |
| 175 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 176 | strcat(dst_aligned, src_aligned); |
| 177 | dst_aligned[nbytes - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 181 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 182 | BIONIC_BENCHMARK(BM_string_strcat_seek_only); |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 183 | |
| 184 | static void BM_string_strcat_half_copy_half_seek(benchmark::State& state) { |
| 185 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 186 | const size_t src_alignment = state.range(1); |
| 187 | const size_t dst_alignment = state.range(2); |
| 188 | |
| 189 | std::vector<char> src; |
| 190 | std::vector<char> dst; |
| 191 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes / 2, 'x'); |
| 192 | char* dst_aligned = GetAlignedPtrFilled(&dst, dst_alignment, nbytes, 'y'); |
| 193 | src_aligned[nbytes / 2 - 1] = '\0'; |
| 194 | dst_aligned[nbytes / 2 - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 195 | |
| 196 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 197 | strcat(dst_aligned, src_aligned); |
| 198 | dst_aligned[nbytes / 2 - 1] = '\0'; |
Anders Lewis | a99d052 | 2017-06-12 11:24:01 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 202 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 203 | BIONIC_BENCHMARK(BM_string_strcat_half_copy_half_seek); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 204 | |
| 205 | static void BM_string_strcpy(benchmark::State& state) { |
| 206 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 207 | const size_t src_alignment = state.range(1); |
| 208 | const size_t dst_alignment = state.range(2); |
| 209 | |
| 210 | std::vector<char> src; |
| 211 | std::vector<char> dst; |
| 212 | char* src_aligned = GetAlignedPtrFilled(&src, src_alignment, nbytes, 'x'); |
| 213 | char* dst_aligned = GetAlignedPtr(&dst, dst_alignment, nbytes); |
| 214 | src_aligned[nbytes - 1] = '\0'; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 215 | |
| 216 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 217 | strcpy(dst_aligned, src_aligned); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 221 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 222 | BIONIC_BENCHMARK(BM_string_strcpy); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 223 | |
| 224 | static void BM_string_strcmp(benchmark::State& state) { |
| 225 | const size_t nbytes = state.range(0); |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 226 | const size_t s1_alignment = state.range(1); |
| 227 | const size_t s2_alignment = state.range(2); |
| 228 | |
| 229 | std::vector<char> s1; |
| 230 | std::vector<char> s2; |
| 231 | char* s1_aligned = GetAlignedPtrFilled(&s1, s1_alignment, nbytes, 'x'); |
| 232 | char* s2_aligned = GetAlignedPtrFilled(&s2, s2_alignment, nbytes, 'x'); |
| 233 | s1_aligned[nbytes - 1] = '\0'; |
| 234 | s2_aligned[nbytes - 1] = '\0'; |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 235 | |
| 236 | volatile int c __attribute__((unused)); |
| 237 | while (state.KeepRunning()) { |
Anders Lewis | f4447b9 | 2017-06-23 15:53:59 -0700 | [diff] [blame] | 238 | c = strcmp(s1_aligned, s2_aligned); |
Anders Lewis | 1c487e1 | 2017-06-12 12:33:06 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 242 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 243 | BIONIC_BENCHMARK(BM_string_strcmp); |
Anders Lewis | ac4f4b4 | 2017-08-08 18:29:51 -0700 | [diff] [blame^] | 244 | |
| 245 | static void BM_string_strstr(benchmark::State& state) { |
| 246 | const size_t nbytes = state.range(0); |
| 247 | const size_t haystack_alignment = state.range(1); |
| 248 | const size_t needle_alignment = state.range(2); |
| 249 | |
| 250 | std::vector<char> haystack; |
| 251 | std::vector<char> needle; |
| 252 | char* haystack_aligned = GetAlignedPtrFilled(&haystack, haystack_alignment, nbytes, 'x'); |
| 253 | char* needle_aligned = GetAlignedPtrFilled(&needle, needle_alignment, |
| 254 | std::min(nbytes, static_cast<size_t>(5)), 'x'); |
| 255 | |
| 256 | if (nbytes / 4 > 2) { |
| 257 | for (size_t i = 0; nbytes / 4 >= 2 && i < nbytes / 4 - 2; i++) { |
| 258 | haystack_aligned[4 * i + 3] = 'y'; |
| 259 | } |
| 260 | } |
| 261 | haystack_aligned[nbytes - 1] = '\0'; |
| 262 | needle_aligned[needle.size() - 1] = '\0'; |
| 263 | |
| 264 | while (state.KeepRunning()) { |
| 265 | if (strstr(haystack_aligned, needle_aligned) == nullptr) { |
| 266 | abort(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 271 | } |
| 272 | BIONIC_BENCHMARK(BM_string_strstr); |
| 273 | |
| 274 | static void BM_string_strchr(benchmark::State& state) { |
| 275 | const size_t nbytes = state.range(0); |
| 276 | const size_t haystack_alignment = state.range(1); |
| 277 | |
| 278 | std::vector<char> haystack; |
| 279 | char* haystack_aligned = GetAlignedPtrFilled(&haystack, haystack_alignment, nbytes, 'x'); |
| 280 | |
| 281 | while (state.KeepRunning()) { |
| 282 | if (strchr(haystack_aligned, 'y') != nullptr) { |
| 283 | abort(); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); |
| 288 | } |
| 289 | BIONIC_BENCHMARK(BM_string_strchr); |