| 193 | } |
| 194 | |
| 195 | static void BenchmarkStreamingWrites(benchmark::State& state, |
| 196 | const std::valarray<int64_t>& sizes, |
| 197 | io::OutputStream* stream, |
| 198 | BackgroundReader* reader = nullptr) { |
| 199 | const std::string datastr(sizes.max(), 'x'); |
| 200 | const void* data = datastr.data(); |
| 201 | const int64_t sum_sizes = sizes.sum(); |
| 202 | |
| 203 | while (state.KeepRunning()) { |
| 204 | for (const int64_t size : sizes) { |
| 205 | ABORT_NOT_OK(stream->Write(data, size)); |
| 206 | } |
| 207 | } |
| 208 | // For Windows: need to close writer before joining reader thread. |
| 209 | ABORT_NOT_OK(stream->Close()); |
| 210 | |
| 211 | const int64_t total_bytes = static_cast<int64_t>(state.iterations()) * sum_sizes; |
| 212 | state.SetBytesProcessed(total_bytes); |
| 213 | |
| 214 | if (reader != nullptr) { |
| 215 | // Wake up and stop |
| 216 | reader->Stop(); |
| 217 | reader->Join(); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Benchmark writing to /dev/null |
| 222 | // |
no test coverage detected