From 783c993fb5f3883946d297ebf43600253470bda3 Mon Sep 17 00:00:00 2001 From: NageshPatel978 Date: Sun, 22 Nov 2026 03:07:15 +0530 Subject: [PATCH 1/4] GH-55711: [C++][Parquet] More ALP benchmarking for different input data --- cpp/src/parquet/encoding_benchmark.cc | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/cpp/src/parquet/encoding_benchmark.cc b/cpp/src/parquet/encoding_benchmark.cc index 137c0f8a6fc8..b5d7cd62a3a8 100644 --- a/cpp/src/parquet/encoding_benchmark.cc +++ b/cpp/src/parquet/encoding_benchmark.cc @@ -729,6 +729,73 @@ 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 number of decimals +// and the share of values that cannot be encoded that way (exceptions). +template +static std::vector MakeAlpInput(int64_t length, int decimals, int exception_percent) { + std::default_random_engine gen(/*seed=*/42); + std::uniform_int_distribution dist_digits(0, 100000); + std::uniform_real_distribution dist_random(0, 1000); + std::bernoulli_distribution dist_exception(exception_percent / 100.0); + const T scale = static_cast(std::pow(10.0, decimals)); + std::vector values(length); + for (auto& v : values) { + v = dist_exception(gen) ? dist_random(gen) : static_cast(dist_digits(gen)) / scale; + } + return values; +} + +template +static void BM_AlpEncodingVaried(benchmark::State& state) { + using T = typename DType::c_type; + std::vector values = MakeAlpInput( + state.range(0), static_cast(state.range(1)), static_cast(state.range(2))); + auto encoder = MakeTypedEncoder(Encoding::ALP); + for (auto _ : state) { + encoder->Put(values.data(), static_cast(values.size())); + encoder->FlushValues(); + } + state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T)); + state.SetItemsProcessed(state.iterations() * values.size()); +} + +template +static void BM_AlpDecodingVaried(benchmark::State& state) { + using T = typename DType::c_type; + std::vector values = MakeAlpInput( + state.range(0), static_cast(state.range(1)), static_cast(state.range(2))); + auto encoder = MakeTypedEncoder(Encoding::ALP); + encoder->Put(values.data(), static_cast(values.size())); + std::shared_ptr buf = encoder->FlushValues(); + auto decoder = MakeTypedDecoder(Encoding::ALP); + std::vector output(values.size()); + for (auto _ : state) { + decoder->SetData(static_cast(values.size()), buf->data(), + static_cast(buf->size())); + decoder->Decode(output.data(), static_cast(values.size())); + benchmark::ClobberMemory(); + } + state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T)); + state.SetItemsProcessed(state.iterations() * values.size()); + state.counters["compression_ratio"] = + static_cast(values.size() * sizeof(T)) / buf->size(); +} + +static void AlpCustomArguments(benchmark::internal::Benchmark* b) { + for (int num_values : {MIN_RANGE, MAX_RANGE}) { + for (int decimals : {1, 4}) { + for (int exception_percent : {0, 1, 10, 50, 100}) { + b->Args({num_values, decimals, exception_percent}); + } + } + } + b->ArgNames({"num-values", "decimals", "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 From 65ec9f20fd08d9143b0d85d2bcdde35225498363 Mon Sep 17 00:00:00 2001 From: NageshPatel978 Date: Sun, 22 Nov 2026 15:39:07 +0530 Subject: [PATCH 2/4] Address review comments on ALP benchmarks --- cpp/src/parquet/encoding_benchmark.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cpp/src/parquet/encoding_benchmark.cc b/cpp/src/parquet/encoding_benchmark.cc index b5d7cd62a3a8..797fbd07aeb3 100644 --- a/cpp/src/parquet/encoding_benchmark.cc +++ b/cpp/src/parquet/encoding_benchmark.cc @@ -734,13 +734,14 @@ BENCHMARK(BM_AlpDecodingDouble)->Range(MIN_RANGE, MAX_RANGE); template static std::vector MakeAlpInput(int64_t length, int decimals, int exception_percent) { std::default_random_engine gen(/*seed=*/42); - std::uniform_int_distribution dist_digits(0, 100000); + const int64_t max_digits = static_cast(std::pow(10.0, 3 + decimals)); + std::uniform_int_distribution dist_digits(0, max_digits - 1); std::uniform_real_distribution dist_random(0, 1000); std::bernoulli_distribution dist_exception(exception_percent / 100.0); - const T scale = static_cast(std::pow(10.0, decimals)); + const T scale = static_cast(std::pow(10.0, -decimals)); std::vector values(length); for (auto& v : values) { - v = dist_exception(gen) ? dist_random(gen) : static_cast(dist_digits(gen)) / scale; + v = dist_exception(gen) ? dist_random(gen) : static_cast(dist_digits(gen)) * scale; } return values; } @@ -751,12 +752,15 @@ static void BM_AlpEncodingVaried(benchmark::State& state) { std::vector values = MakeAlpInput( state.range(0), static_cast(state.range(1)), static_cast(state.range(2))); auto encoder = MakeTypedEncoder(Encoding::ALP); + std::shared_ptr buf; for (auto _ : state) { encoder->Put(values.data(), static_cast(values.size())); - encoder->FlushValues(); + buf = encoder->FlushValues(); } state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T)); state.SetItemsProcessed(state.iterations() * values.size()); + state.counters["compression_ratio"] = + static_cast(values.size() * sizeof(T)) / buf->size(); } template @@ -782,14 +786,10 @@ static void BM_AlpDecodingVaried(benchmark::State& state) { } static void AlpCustomArguments(benchmark::internal::Benchmark* b) { - for (int num_values : {MIN_RANGE, MAX_RANGE}) { - for (int decimals : {1, 4}) { - for (int exception_percent : {0, 1, 10, 50, 100}) { - b->Args({num_values, decimals, exception_percent}); - } - } - } - b->ArgNames({"num-values", "decimals", "exception-percent"}); + b->ArgsProduct({benchmark::CreateRange(MIN_RANGE, MAX_RANGE, /*multi=*/8), + {1, 4}, + {0, 1, 10, 50, 100}}) + ->ArgNames({"num-values", "decimals", "exception-percent"}); } BENCHMARK_TEMPLATE(BM_AlpEncodingVaried, FloatType)->Apply(AlpCustomArguments); From 401e83b51795d5252038b5ff8abd313194aa3d0a Mon Sep 17 00:00:00 2001 From: NageshPatel978 Date: Sun, 22 Nov 2026 16:01:30 +0530 Subject: [PATCH 3/4] Trim ALP benchmark matrix, use signed values and a deterministic RNG --- cpp/src/parquet/encoding_benchmark.cc | 34 ++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/cpp/src/parquet/encoding_benchmark.cc b/cpp/src/parquet/encoding_benchmark.cc index 797fbd07aeb3..4a404e90fa0d 100644 --- a/cpp/src/parquet/encoding_benchmark.cc +++ b/cpp/src/parquet/encoding_benchmark.cc @@ -729,16 +729,18 @@ 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 number of decimals -// and the share of values that cannot be encoded that way (exceptions). + +// 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 -static std::vector MakeAlpInput(int64_t length, int decimals, int exception_percent) { - std::default_random_engine gen(/*seed=*/42); - const int64_t max_digits = static_cast(std::pow(10.0, 3 + decimals)); - std::uniform_int_distribution dist_digits(0, max_digits - 1); - std::uniform_real_distribution dist_random(0, 1000); +static std::vector MakeAlpInput(int64_t length, int exception_percent) { + constexpr int kDecimals = 2; + std::mt19937_64 gen(/*seed=*/42); + std::uniform_int_distribution dist_digits(-100000, 100000); + std::uniform_real_distribution dist_random(-1000, 1000); std::bernoulli_distribution dist_exception(exception_percent / 100.0); - const T scale = static_cast(std::pow(10.0, -decimals)); + const T scale = static_cast(std::pow(10.0, -kDecimals)); std::vector values(length); for (auto& v : values) { v = dist_exception(gen) ? dist_random(gen) : static_cast(dist_digits(gen)) * scale; @@ -749,13 +751,14 @@ static std::vector MakeAlpInput(int64_t length, int decimals, int exception_p template static void BM_AlpEncodingVaried(benchmark::State& state) { using T = typename DType::c_type; - std::vector values = MakeAlpInput( - state.range(0), static_cast(state.range(1)), static_cast(state.range(2))); + std::vector values = + MakeAlpInput(state.range(0), static_cast(state.range(1))); auto encoder = MakeTypedEncoder(Encoding::ALP); std::shared_ptr buf; for (auto _ : state) { encoder->Put(values.data(), static_cast(values.size())); buf = encoder->FlushValues(); + ::benchmark::DoNotOptimize(buf); } state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T)); state.SetItemsProcessed(state.iterations() * values.size()); @@ -766,8 +769,8 @@ static void BM_AlpEncodingVaried(benchmark::State& state) { template static void BM_AlpDecodingVaried(benchmark::State& state) { using T = typename DType::c_type; - std::vector values = MakeAlpInput( - state.range(0), static_cast(state.range(1)), static_cast(state.range(2))); + std::vector values = + MakeAlpInput(state.range(0), static_cast(state.range(1))); auto encoder = MakeTypedEncoder(Encoding::ALP); encoder->Put(values.data(), static_cast(values.size())); std::shared_ptr buf = encoder->FlushValues(); @@ -786,10 +789,9 @@ static void BM_AlpDecodingVaried(benchmark::State& state) { } static void AlpCustomArguments(benchmark::internal::Benchmark* b) { - b->ArgsProduct({benchmark::CreateRange(MIN_RANGE, MAX_RANGE, /*multi=*/8), - {1, 4}, - {0, 1, 10, 50, 100}}) - ->ArgNames({"num-values", "decimals", "exception-percent"}); + b->ArgsProduct( + {benchmark::CreateRange(MIN_RANGE, MAX_RANGE, /*multi=*/8), {0, 1, 10, 100}}) + ->ArgNames({"num-values", "exception-percent"}); } BENCHMARK_TEMPLATE(BM_AlpEncodingVaried, FloatType)->Apply(AlpCustomArguments); From e236ff75520f740cf45428f251094fad01a8a538 Mon Sep 17 00:00:00 2001 From: NageshPatel978 Date: Mon, 23 Nov 2026 20:08:52 +0530 Subject: [PATCH 4/4] Reduce ALP benchmark parameters --- cpp/src/parquet/encoding_benchmark.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/parquet/encoding_benchmark.cc b/cpp/src/parquet/encoding_benchmark.cc index 4a404e90fa0d..bf209ea37967 100644 --- a/cpp/src/parquet/encoding_benchmark.cc +++ b/cpp/src/parquet/encoding_benchmark.cc @@ -789,8 +789,7 @@ static void BM_AlpDecodingVaried(benchmark::State& state) { } static void AlpCustomArguments(benchmark::internal::Benchmark* b) { - b->ArgsProduct( - {benchmark::CreateRange(MIN_RANGE, MAX_RANGE, /*multi=*/8), {0, 1, 10, 100}}) + b->ArgsProduct({{MIN_RANGE, MAX_RANGE}, {0, 1, 10}}) ->ArgNames({"num-values", "exception-percent"}); }