westonpace commented on code in PR #13314:
URL: https://github.com/apache/arrow/pull/13314#discussion_r893314915


##########
cpp/src/arrow/compute/exec/project_benchmark.cc:
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <condition_variable>
+#include <mutex>
+
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/cast.h"
+#include "arrow/compute/exec.h"
+#include "arrow/compute/exec/expression.h"
+#include "arrow/compute/exec/options.h"
+#include "arrow/compute/exec/task_util.h"
+#include "arrow/compute/exec/test_util.h"
+#include "arrow/dataset/partition.h"
+#include "arrow/testing/future_util.h"
+#include "arrow/testing/generator.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/type.h"
+
+namespace arrow {
+namespace compute {
+
+static constexpr int64_t total_batch_size = 1e6;

Review Comment:
   ```suggestion
   static constexpr int64_t kTotalBatchSize = 1e6;
   ```
   Sorry I missed this on the first go-through.  Constants follow kNamingCase
   
   Reference: https://google.github.io/styleguide/cppguide.html#Constant_Names



##########
cpp/src/arrow/compute/exec/project_benchmark.cc:
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <condition_variable>
+#include <mutex>
+
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/cast.h"
+#include "arrow/compute/exec.h"
+#include "arrow/compute/exec/expression.h"
+#include "arrow/compute/exec/options.h"
+#include "arrow/compute/exec/task_util.h"
+#include "arrow/compute/exec/test_util.h"
+#include "arrow/dataset/partition.h"
+#include "arrow/testing/future_util.h"
+#include "arrow/testing/generator.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/type.h"
+
+namespace arrow {
+namespace compute {
+
+static constexpr int64_t total_batch_size = 1e6;
+
+static void ProjectionOverhead(benchmark::State& state, Expression expr) {
+  const auto batch_size = static_cast<int32_t>(state.range(0));
+  const auto num_batches = total_batch_size / batch_size;
+
+  auto data = MakeRandomBatches(schema({field("i64", int64()), field("bool", 
boolean())}),
+                                num_batches, batch_size);
+  ExecContext ctx(default_memory_pool(), arrow::internal::GetCpuThreadPool());
+  for (auto _ : state) {
+    state.PauseTiming();
+    ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(&ctx));
+    AsyncGenerator<util::optional<ExecBatch>> sink_gen;
+    ASSERT_OK(Declaration::Sequence(
+                  {
+                      {"source",
+                       SourceNodeOptions{data.schema,
+                                         data.gen(/*parallel=*/true, 
/*slow=*/false)},
+                       "custom_source_label"},
+                      {"project", ProjectNodeOptions{{
+                                      expr,
+                                  }}},
+                      {"sink", SinkNodeOptions{&sink_gen}, 
"custom_sink_label"},
+                  })
+                  .AddToPlan(plan.get()));
+    state.ResumeTiming();
+    ASSERT_FINISHES_OK(StartAndCollect(plan.get(), sink_gen));
+  }
+  state.counters["rows_per_second"] = benchmark::Counter(
+      static_cast<double>(state.iterations() * num_batches * batch_size),
+      benchmark::Counter::kIsRate);
+
+  state.counters["batches_per_second"] = benchmark::Counter(
+      static_cast<double>(state.iterations() * num_batches), 
benchmark::Counter::kIsRate);
+}
+
+static void ProjectionOverheadIsolated(benchmark::State& state, Expression 
expr) {
+  const auto batch_size = static_cast<int32_t>(state.range(0));
+  const auto num_batches = total_batch_size / batch_size;
+
+  auto data = MakeRandomBatches(schema({field("i64", int64()), field("bool", 
boolean())}),
+                                num_batches, batch_size);
+  ExecContext ctx(default_memory_pool(), arrow::internal::GetCpuThreadPool());
+  for (auto _ : state) {
+    state.PauseTiming();
+
+    AsyncGenerator<util::optional<ExecBatch>> sink_gen;
+    ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(&ctx));
+    // Source and sink nodes have no effect on the benchmark.
+    // Used for dummy purposes as they are referenced in InputReceived and 
InputFinished.
+    ASSERT_OK_AND_ASSIGN(
+        auto sn, MakeExecNode("source", plan.get(), {},
+                              SourceNodeOptions{data.schema, 
data.gen(/*parallel=*/true,
+                                                                      
/*slow=*/false)}));
+    ASSERT_OK_AND_ASSIGN(auto pn, MakeExecNode("project", plan.get(), {sn},

Review Comment:
   Minor nit: Let's try and avoid overly short variable names (e.g. `sn`, `pn`, 
`tp`).  I suppose this is somewhat hypocritical of me since I used `cv` but 
even that could be something like `all_tasks_finished_cv`.
   
   Reference: https://google.github.io/styleguide/cppguide.html#Constant_Names



##########
cpp/src/arrow/compute/exec/project_benchmark.cc:
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <condition_variable>
+#include <mutex>
+
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/cast.h"
+#include "arrow/compute/exec.h"
+#include "arrow/compute/exec/expression.h"
+#include "arrow/compute/exec/options.h"
+#include "arrow/compute/exec/task_util.h"
+#include "arrow/compute/exec/test_util.h"
+#include "arrow/dataset/partition.h"
+#include "arrow/testing/future_util.h"
+#include "arrow/testing/generator.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/type.h"
+
+namespace arrow {
+namespace compute {
+
+static constexpr int64_t total_batch_size = 1e6;
+
+static void ProjectionOverhead(benchmark::State& state, Expression expr) {
+  const auto batch_size = static_cast<int32_t>(state.range(0));
+  const auto num_batches = total_batch_size / batch_size;
+
+  auto data = MakeRandomBatches(schema({field("i64", int64()), field("bool", 
boolean())}),
+                                num_batches, batch_size);
+  ExecContext ctx(default_memory_pool(), arrow::internal::GetCpuThreadPool());
+  for (auto _ : state) {
+    state.PauseTiming();
+    ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(&ctx));
+    AsyncGenerator<util::optional<ExecBatch>> sink_gen;
+    ASSERT_OK(Declaration::Sequence(
+                  {
+                      {"source",
+                       SourceNodeOptions{data.schema,
+                                         data.gen(/*parallel=*/true, 
/*slow=*/false)},
+                       "custom_source_label"},
+                      {"project", ProjectNodeOptions{{
+                                      expr,
+                                  }}},
+                      {"sink", SinkNodeOptions{&sink_gen}, 
"custom_sink_label"},
+                  })
+                  .AddToPlan(plan.get()));
+    state.ResumeTiming();
+    ASSERT_FINISHES_OK(StartAndCollect(plan.get(), sink_gen));
+  }
+  state.counters["rows_per_second"] = benchmark::Counter(
+      static_cast<double>(state.iterations() * num_batches * batch_size),
+      benchmark::Counter::kIsRate);
+
+  state.counters["batches_per_second"] = benchmark::Counter(
+      static_cast<double>(state.iterations() * num_batches), 
benchmark::Counter::kIsRate);
+}
+
+static void ProjectionOverheadIsolated(benchmark::State& state, Expression 
expr) {
+  const auto batch_size = static_cast<int32_t>(state.range(0));
+  const auto num_batches = total_batch_size / batch_size;
+
+  auto data = MakeRandomBatches(schema({field("i64", int64()), field("bool", 
boolean())}),
+                                num_batches, batch_size);

Review Comment:
   Minor nit: try not to use `auto` when the return type isn't immediately 
obvious (e.g. `make_shared` or `dynamic_cast`) or unless `auto` is needed for 
correctness.
   
   To be fair, we have a somewhat mixed consistency within the code base at the 
moment, but our style guide is to be explicit.
   
   Reference: https://google.github.io/styleguide/cppguide.html#Type_deduction



-- 
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