MCPcopy Create free account
hub / github.com/apache/arrow / CompressedInputStreamBenchmark

Function CompressedInputStreamBenchmark

cpp/src/arrow/io/compressed_benchmark.cc:101–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99
100template <typename BufReader, BufferReadMode Mode>
101static void CompressedInputStreamBenchmark(::benchmark::State& state,
102 Compression::type compression) {
103 const int64_t input_size = state.range(0);
104 const int64_t batch_size = state.range(1);
105
106 const std::vector<uint8_t> data = MakeCompressibleData(static_cast<int>(input_size));
107 auto codec = ::arrow::util::Codec::Create(compression).ValueOrDie();
108 int64_t max_compress_len =
109 codec->MaxCompressedLen(static_cast<int64_t>(data.size()), data.data());
110 std::shared_ptr<::arrow::ResizableBuffer> buf =
111 ::arrow::AllocateResizableBuffer(max_compress_len).ValueOrDie();
112 const int64_t compressed_length =
113 codec
114 ->Compress(static_cast<int64_t>(data.size()), data.data(), max_compress_len,
115 buf->mutable_data())
116 .ValueOrDie();
117 ABORT_NOT_OK(buf->Resize(compressed_length));
118 for (auto _ : state) {
119 state.PauseTiming();
120 auto reader = std::make_shared<BufReader>(buf);
121 [[maybe_unused]] std::unique_ptr<Buffer> read_buffer;
122 if constexpr (Mode == BufferReadMode::ProvidedByCaller) {
123 read_buffer = ::arrow::AllocateBuffer(batch_size).ValueOrDie();
124 }
125 state.ResumeTiming();
126 // Put `CompressedInputStream::Make` in timing.
127 auto input_stream =
128 ::arrow::io::CompressedInputStream::Make(codec.get(), reader).ValueOrDie();
129 auto remaining_size = input_size;
130 while (remaining_size > 0) {
131 if constexpr (Mode == BufferReadMode::ProvidedByCaller) {
132 auto value = input_stream->Read(batch_size, read_buffer->mutable_data());
133 ABORT_NOT_OK(value);
134 remaining_size -= value.ValueOrDie();
135 } else {
136 auto value = input_stream->Read(batch_size);
137 ABORT_NOT_OK(value);
138 remaining_size -= value.ValueOrDie()->size();
139 }
140 }
141 }
142 state.SetBytesProcessed(input_size * state.iterations());
143}
144
145template <Compression::type kCompression>
146static void CompressedInputStreamZeroCopyBufferProvidedByCaller(

Callers

nothing calls this directly

Calls 13

AllocateResizableBufferFunction · 0.85
ValueOrDieMethod · 0.80
MakeCompressibleDataFunction · 0.70
AllocateBufferFunction · 0.50
MakeFunction · 0.50
MaxCompressedLenMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
CompressMethod · 0.45
mutable_dataMethod · 0.45
ResizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected