iChauster commented on code in PR #13366: URL: https://github.com/apache/arrow/pull/13366#discussion_r904131551
########## cpp/src/arrow/compute/exec/filter_benchmark.cc: ########## @@ -0,0 +1,176 @@ +// 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 kTotalBatchSize = 1000000; + +static void FilterOverhead(benchmark::State& state, Expression expr) { + const int32_t batch_size = static_cast<int32_t>(state.range(0)); + const int32_t num_batches = kTotalBatchSize / batch_size; + + arrow::compute::BatchesWithSchema 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(std::shared_ptr<arrow::compute::ExecPlan> 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"}, + {"filter", + FilterNodeOptions{ + 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 FilterOverheadIsolated(benchmark::State& state, Expression expr) { + const int32_t batch_size = static_cast<int32_t>(state.range(0)); + const int32_t num_batches = kTotalBatchSize / batch_size; + + arrow::compute::BatchesWithSchema 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(std::shared_ptr<arrow::compute::ExecPlan> 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( + arrow::compute::ExecNode * source_node, + MakeExecNode("source", plan.get(), {}, + SourceNodeOptions{data.schema, data.gen(/*parallel=*/true, + /*slow=*/false)})); + ASSERT_OK_AND_ASSIGN(arrow::compute::ExecNode * project_node, Review Comment: Moved most of the logic into `benchmark_util.h`, reflected in `project_benchmark.cc` as well. -- 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]
