mapleFU commented on code in PR #55714:
URL: https://github.com/apache/arrow/pull/55714#discussion_r4656937916


##########
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 <typename T>
+static std::vector<T> MakeAlpInput(int64_t length, int decimals, int 
exception_percent) {
+  std::default_random_engine gen(/*seed=*/42);
+  std::uniform_int_distribution<int64_t> dist_digits(0, 100000);

Review Comment:
   We have 1,4 as decimals, however, only [0, 100000) is used 🤔



##########
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 <typename T>
+static std::vector<T> MakeAlpInput(int64_t length, int decimals, int 
exception_percent) {
+  std::default_random_engine gen(/*seed=*/42);
+  std::uniform_int_distribution<int64_t> dist_digits(0, 100000);
+  std::uniform_real_distribution<T> dist_random(0, 1000);
+  std::bernoulli_distribution dist_exception(exception_percent / 100.0);
+  const T scale = static_cast<T>(std::pow(10.0, decimals));
+  std::vector<T> values(length);
+  for (auto& v : values) {
+    v = dist_exception(gen) ? dist_random(gen) : 
static_cast<T>(dist_digits(gen)) / scale;

Review Comment:
   > Float shows a much lower ratio at 0% exceptions (~1.2); I haven't 
investigated why
   
   I think `* static_cast<T>(std::pow(10.0, -decimals))` should be used in this 
scenario, since ` / 100.0f * 100.0f` might not get the original value back ( 
`5.0f / 100.0f != 5.0f * 0.01f`) ?



##########
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 <typename T>
+static std::vector<T> MakeAlpInput(int64_t length, int decimals, int 
exception_percent) {
+  std::default_random_engine gen(/*seed=*/42);
+  std::uniform_int_distribution<int64_t> dist_digits(0, 100000);
+  std::uniform_real_distribution<T> dist_random(0, 1000);
+  std::bernoulli_distribution dist_exception(exception_percent / 100.0);
+  const T scale = static_cast<T>(std::pow(10.0, decimals));
+  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)), 
static_cast<int>(state.range(2)));
+  auto encoder = MakeTypedEncoder<DType>(Encoding::ALP);
+  for (auto _ : state) {
+    encoder->Put(values.data(), static_cast<int>(values.size()));
+    encoder->FlushValues();
+  }
+  state.SetBytesProcessed(state.iterations() * values.size() * sizeof(T));
+  state.SetItemsProcessed(state.iterations() * values.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)), 
static_cast<int>(state.range(2)));
+  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) {
+  for (int num_values : {MIN_RANGE, MAX_RANGE}) {

Review Comment:
   Does this matches `Range`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to