This is an automated email from the ASF dual-hosted git repository.
pitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 9f43f4e3d1f GH-55711: [C++][Parquet] More ALP benchmarking for
different input data (#55714)
9f43f4e3d1f is described below
commit 9f43f4e3d1ffd7fafa7ec8865903222368a65e10
Author: NageshPatel978 <[email protected]>
AuthorDate: Tue Nov 24 18:56:13 2026 +0530
GH-55711: [C++][Parquet] More ALP benchmarking for different input data
(#55714)
### Rationale for this change
The existing ALP benchmarks encode a single repeated value (64.0), so
decoding does almost no real work and the numbers don't reflect real data (see
#55711).
### What changes are included in this PR?
Adds ALP encoding and decoding benchmarks for float and double with varied
input:
- number of values (1024 and 65536)
- exception percentage (0, 1, 10), i.e. values that don't fit ALP's pattern
Decimal values are signed, with 2 decimals, generated as `digits *
10^-decimals` (how ALP decodes them) from a deterministic `std::mt19937_64`.
Encoding and decoding benchmarks both report a `compression_ratio` counter. The
existing constant-value benchmarks are unchanged.
### Are these changes tested?
Benchmarks only; no library code changed. Run on x86_64, AMD Ryzen 7
7435HS, Linux, GCC 16.2.0, Release build, CPU scaling enabled. Timings are
approximate, and decode numbers with no exceptions may be
memory-bandwidth-bound, so they will differ by chip.
Decoding, 65536 values:
| | exceptions | speed | compression ratio |
|---|---|---|---|
| double | 0% | ~10.5 GiB/s | ~3.5 |
| double | 1% | ~10.2 GiB/s | ~3.4 |
| double | 10% | ~8.8 GiB/s | ~2.4 |
| float | 0% | ~5.7 GiB/s | ~1.8 |
| float | 1% | ~5.4 GiB/s | ~1.7 |
| float | 10% | ~4.8 GiB/s | ~1.4 |
### Are there any user-facing changes?
No.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
I used Claude to help draft the benchmark code and this description. I
built it, ran the benchmarks and checked the results myself.
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [x] AI
- [ ] Not reviewed
* GitHub Issue: #55711
Authored-by: NageshPatel978 <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
cpp/src/parquet/encoding_benchmark.cc | 68 +++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/cpp/src/parquet/encoding_benchmark.cc
b/cpp/src/parquet/encoding_benchmark.cc
index 137c0f8a6fc..bf209ea3796 100644
--- a/cpp/src/parquet/encoding_benchmark.cc
+++ b/cpp/src/parquet/encoding_benchmark.cc
@@ -730,6 +730,74 @@ static void BM_AlpDecodingDouble(benchmark::State& state) {
BENCHMARK(BM_AlpDecodingDouble)->Range(MIN_RANGE, MAX_RANGE);
+// ALP speed depends on how "decimal-like" the data is, so vary the share of
values that
+// cannot be encoded that way (exceptions). Decimal values are generated as
+// digits * 10^-decimals, which is how ALP decodes them.
+template <typename T>
+static std::vector<T> MakeAlpInput(int64_t length, int exception_percent) {
+ constexpr int kDecimals = 2;
+ std::mt19937_64 gen(/*seed=*/42);
+ std::uniform_int_distribution<int64_t> dist_digits(-100000, 100000);
+ std::uniform_real_distribution<T> dist_random(-1000, 1000);
+ std::bernoulli_distribution dist_exception(exception_percent / 100.0);
+ const T scale = static_cast<T>(std::pow(10.0, -kDecimals));
+ std::vector<T> values(length);
+ for (auto& v : values) {
+ v = dist_exception(gen) ? dist_random(gen) :
static_cast<T>(dist_digits(gen)) * scale;
+ }
+ return values;
+}
+
+template <typename DType>
+static void BM_AlpEncodingVaried(benchmark::State& state) {
+ using T = typename DType::c_type;
+ std::vector<T> values =
+ MakeAlpInput<T>(state.range(0), static_cast<int>(state.range(1)));
+ auto encoder = MakeTypedEncoder<DType>(Encoding::ALP);
+ std::shared_ptr<Buffer> buf;
+ for (auto _ : state) {
+ encoder->Put(values.data(), static_cast<int>(values.size()));
+ buf = encoder->FlushValues();
+ ::benchmark::DoNotOptimize(buf);
+ }
+ state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T));
+ state.SetItemsProcessed(state.iterations() * values.size());
+ state.counters["compression_ratio"] =
+ static_cast<double>(values.size() * sizeof(T)) / buf->size();
+}
+
+template <typename DType>
+static void BM_AlpDecodingVaried(benchmark::State& state) {
+ using T = typename DType::c_type;
+ std::vector<T> values =
+ MakeAlpInput<T>(state.range(0), static_cast<int>(state.range(1)));
+ auto encoder = MakeTypedEncoder<DType>(Encoding::ALP);
+ encoder->Put(values.data(), static_cast<int>(values.size()));
+ std::shared_ptr<Buffer> buf = encoder->FlushValues();
+ auto decoder = MakeTypedDecoder<DType>(Encoding::ALP);
+ std::vector<T> output(values.size());
+ for (auto _ : state) {
+ decoder->SetData(static_cast<int>(values.size()), buf->data(),
+ static_cast<int>(buf->size()));
+ decoder->Decode(output.data(), static_cast<int>(values.size()));
+ benchmark::ClobberMemory();
+ }
+ state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T));
+ state.SetItemsProcessed(state.iterations() * values.size());
+ state.counters["compression_ratio"] =
+ static_cast<double>(values.size() * sizeof(T)) / buf->size();
+}
+
+static void AlpCustomArguments(benchmark::internal::Benchmark* b) {
+ b->ArgsProduct({{MIN_RANGE, MAX_RANGE}, {0, 1, 10}})
+ ->ArgNames({"num-values", "exception-percent"});
+}
+
+BENCHMARK_TEMPLATE(BM_AlpEncodingVaried, FloatType)->Apply(AlpCustomArguments);
+BENCHMARK_TEMPLATE(BM_AlpEncodingVaried,
DoubleType)->Apply(AlpCustomArguments);
+BENCHMARK_TEMPLATE(BM_AlpDecodingVaried, FloatType)->Apply(AlpCustomArguments);
+BENCHMARK_TEMPLATE(BM_AlpDecodingVaried,
DoubleType)->Apply(AlpCustomArguments);
+
// ----------------------------------------------------------------------
// DeltaBitPacking encoding/decoding benchmarks