Generate random text that won't contain the search string, to test worst-case search behavior.
| 155 | // Generate random text that won't contain the search string, |
| 156 | // to test worst-case search behavior. |
| 157 | std::string RandomText(int64_t nbytes) { |
| 158 | static const std::string* const text = []() { |
| 159 | std::string* text = new std::string; |
| 160 | srand(1); |
| 161 | text->resize(16<<20); |
| 162 | for (int64_t i = 0; i < 16<<20; i++) { |
| 163 | // Generate a one-byte rune that isn't a control character (e.g. '\n'). |
| 164 | // Clipping to 0x20 introduces some bias, but we don't need uniformity. |
| 165 | int byte = rand() & 0x7F; |
| 166 | if (byte < 0x20) |
| 167 | byte = 0x20; |
| 168 | (*text)[i] = byte; |
| 169 | } |
| 170 | return text; |
| 171 | }(); |
| 172 | CHECK_LE(nbytes, 16<<20); |
| 173 | return text->substr(0, nbytes); |
| 174 | } |
| 175 | |
| 176 | // Makes text of size nbytes, then calls run to search |
| 177 | // the text for regexp iters times. |
no test coverage detected