| 102 | } |
| 103 | |
| 104 | static void BenchmarkJSONChunkingMultipleBlocks( |
| 105 | benchmark::State& state, // NOLINT non-const reference |
| 106 | const std::shared_ptr<Buffer>& json, ParseOptions options, int64_t block_size) { |
| 107 | auto chunker = MakeChunker(options); |
| 108 | |
| 109 | for (auto _ : state) { |
| 110 | std::shared_ptr<Buffer> partial; |
| 111 | int64_t offset = 0; |
| 112 | while (offset < json->size()) { |
| 113 | const auto slice_size = std::min(block_size, json->size() - offset); |
| 114 | auto block = SliceBuffer(json, offset, slice_size); |
| 115 | offset += slice_size; |
| 116 | if (offset == json->size()) { |
| 117 | // Final block |
| 118 | ABORT_NOT_OK(chunker->ProcessFinal(partial, block, &block, &partial)); |
| 119 | ABORT_NOT_OK(chunker->Process(partial, &block, &partial)); |
| 120 | } else if (partial) { |
| 121 | // Continuation block |
| 122 | ABORT_NOT_OK(chunker->ProcessWithPartial(partial, block, &block, &partial)); |
| 123 | ABORT_NOT_OK(chunker->Process(partial, &block, &partial)); |
| 124 | } else { |
| 125 | // First block |
| 126 | ABORT_NOT_OK(chunker->Process(block, &block, &partial)); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | state.SetBytesProcessed(state.iterations() * json->size()); |
| 132 | state.counters["json_size"] = static_cast<double>(json->size()); |
| 133 | state.counters["block_size"] = static_cast<double>(block_size); |
| 134 | } |
| 135 | |
| 136 | static void ChunkJSONPrettyPrinted( |
| 137 | benchmark::State& state) { // NOLINT non-const reference |
no test coverage detected