From 2a281a8bfa749cdfe00d5325a68ebad648d56a87 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Tue, 5 Mar 2024 10:08:13 +0100 Subject: [PATCH 01/14] Initial commit with a very simple benchmark --- cpp/src/arrow/CMakeLists.txt | 1 + cpp/src/arrow/to_tensor_benchmark.cc | 57 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 cpp/src/arrow/to_tensor_benchmark.cc diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 3d1b621db0e9..17f5e9e57b95 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -1175,6 +1175,7 @@ add_arrow_benchmark(builder_benchmark) add_arrow_benchmark(compare_benchmark) add_arrow_benchmark(memory_pool_benchmark) add_arrow_benchmark(type_benchmark) +add_arrow_benchmark(to_tensor_benchmark) # # Recurse into sub-directories diff --git a/cpp/src/arrow/to_tensor_benchmark.cc b/cpp/src/arrow/to_tensor_benchmark.cc new file mode 100644 index 000000000000..7bda91128e72 --- /dev/null +++ b/cpp/src/arrow/to_tensor_benchmark.cc @@ -0,0 +1,57 @@ +// 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 "benchmark/benchmark.h" + +#include "arrow/record_batch.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/type.h" + +namespace arrow { + +static void RecordBatchUniformTypesSimple( + benchmark::State& state) { // NOLINT non-const reference + const int length = 9; + auto ty = int32(); + + auto f0 = field("f0", ty); + auto f1 = field("f1", ty); + auto f2 = field("f2", ty); + + std::vector> fields = {f0, f1, f2}; + auto schema = ::arrow::schema(fields); + + auto a0 = ArrayFromJSON(ty, "[1, 2, 3, 4, 5, 6, 7, 8, 9]"); + auto a1 = ArrayFromJSON(ty, "[10, 20, 30, 40, 50, 60, 70, 80, 90]"); + auto a2 = ArrayFromJSON(ty, "[100, 100, 100, 100, 100, 100, 100, 100, 100]"); + + auto batch = RecordBatch::Make(schema, length, {a0, a1, a2}); + + ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); + + for (auto _ : state) { + ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); + } + benchmark::DoNotOptimize(tensor); + state.SetItemsProcessed(state.iterations() * batch->num_rows() * batch->num_columns()); + state.SetBytesProcessed(state.iterations() * ty->bit_width() * batch->num_columns() * + batch->num_rows()); +} + +BENCHMARK(RecordBatchUniformTypesSimple); + +} // namespace arrow From e75703d457b8ef78cafc37446024814e12848253 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Wed, 6 Mar 2024 11:27:03 +0100 Subject: [PATCH 02/14] Use templates and bigger data --- cpp/src/arrow/to_tensor_benchmark.cc | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/cpp/src/arrow/to_tensor_benchmark.cc b/cpp/src/arrow/to_tensor_benchmark.cc index 7bda91128e72..d446f0c97f28 100644 --- a/cpp/src/arrow/to_tensor_benchmark.cc +++ b/cpp/src/arrow/to_tensor_benchmark.cc @@ -19,15 +19,14 @@ #include "arrow/record_batch.h" #include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" #include "arrow/type.h" namespace arrow { -static void RecordBatchUniformTypesSimple( - benchmark::State& state) { // NOLINT non-const reference - const int length = 9; - auto ty = int32(); - +template +static void BatchToTensorSimple(benchmark::State& state) { + std::shared_ptr ty = TypeTraits::type_singleton(); auto f0 = field("f0", ty); auto f1 = field("f1", ty); auto f2 = field("f2", ty); @@ -35,11 +34,13 @@ static void RecordBatchUniformTypesSimple( std::vector> fields = {f0, f1, f2}; auto schema = ::arrow::schema(fields); - auto a0 = ArrayFromJSON(ty, "[1, 2, 3, 4, 5, 6, 7, 8, 9]"); - auto a1 = ArrayFromJSON(ty, "[10, 20, 30, 40, 50, 60, 70, 80, 90]"); - auto a2 = ArrayFromJSON(ty, "[100, 100, 100, 100, 100, 100, 100, 100, 100]"); + constexpr int kNumRows = 500; + arrow::random::RandomArrayGenerator gen_{42}; + auto a0 = gen_.ArrayOf(ty, kNumRows); + auto a1 = gen_.ArrayOf(ty, kNumRows); + auto a2 = gen_.ArrayOf(ty, kNumRows); - auto batch = RecordBatch::Make(schema, length, {a0, a1, a2}); + auto batch = RecordBatch::Make(schema, kNumRows, {a0, a1, a2}); ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); @@ -52,6 +53,16 @@ static void RecordBatchUniformTypesSimple( batch->num_rows()); } -BENCHMARK(RecordBatchUniformTypesSimple); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt8Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt16Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt32Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt64Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int8Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int16Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int32Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int64Type); +BENCHMARK_TEMPLATE(BatchToTensorSimple, HalfFloatType); +BENCHMARK_TEMPLATE(BatchToTensorSimple, FloatType); +BENCHMARK_TEMPLATE(BatchToTensorSimple, DoubleType); } // namespace arrow From 8ce1d994dae5beca3c4b75cec01cc15502d4ce6c Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Thu, 7 Mar 2024 14:27:20 +0100 Subject: [PATCH 03/14] Rename benchmark file and make test case much bigger --- cpp/src/arrow/CMakeLists.txt | 2 +- .../{to_tensor_benchmark.cc => tensor_benchmark.cc} | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) rename cpp/src/arrow/{to_tensor_benchmark.cc => tensor_benchmark.cc} (90%) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 17f5e9e57b95..4bf1008af4cd 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -1175,7 +1175,7 @@ add_arrow_benchmark(builder_benchmark) add_arrow_benchmark(compare_benchmark) add_arrow_benchmark(memory_pool_benchmark) add_arrow_benchmark(type_benchmark) -add_arrow_benchmark(to_tensor_benchmark) +add_arrow_benchmark(tensor_benchmark) # # Recurse into sub-directories diff --git a/cpp/src/arrow/to_tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc similarity index 90% rename from cpp/src/arrow/to_tensor_benchmark.cc rename to cpp/src/arrow/tensor_benchmark.cc index d446f0c97f28..7dfdc72a85eb 100644 --- a/cpp/src/arrow/to_tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -34,13 +34,13 @@ static void BatchToTensorSimple(benchmark::State& state) { std::vector> fields = {f0, f1, f2}; auto schema = ::arrow::schema(fields); - constexpr int kNumRows = 500; + constexpr int kNumRows = 100000; arrow::random::RandomArrayGenerator gen_{42}; - auto a0 = gen_.ArrayOf(ty, kNumRows); - auto a1 = gen_.ArrayOf(ty, kNumRows); - auto a2 = gen_.ArrayOf(ty, kNumRows); - - auto batch = RecordBatch::Make(schema, kNumRows, {a0, a1, a2}); + std::vector> columns = {}; + for (int i = 0; i < 100; ++i) { + columns.push_back(gen_.ArrayOf(ty, kNumRows)); + } + auto batch = RecordBatch::Make(schema, kNumRows, columns); ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); From 391547c2613e4473b06fcb5c98f0392b18fe4352 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Wed, 13 Mar 2024 14:19:20 +0100 Subject: [PATCH 04/14] Clean up and add SetArgs --- cpp/src/arrow/tensor_benchmark.cc | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 7dfdc72a85eb..7437eae09a08 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -21,48 +21,49 @@ #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/type.h" +#include "arrow/util/benchmark_util.h" namespace arrow { template static void BatchToTensorSimple(benchmark::State& state) { + RegressionArgs args(state); std::shared_ptr ty = TypeTraits::type_singleton(); - auto f0 = field("f0", ty); - auto f1 = field("f1", ty); - auto f2 = field("f2", ty); - std::vector> fields = {f0, f1, f2}; - auto schema = ::arrow::schema(fields); - - constexpr int kNumRows = 100000; + const int64_t kNumRows = args.size * 8; arrow::random::RandomArrayGenerator gen_{42}; + + std::vector> fields = {}; std::vector> columns = {}; + for (int i = 0; i < 100; ++i) { + fields.push_back(field("f" + std::to_string(i), ty)); columns.push_back(gen_.ArrayOf(ty, kNumRows)); } + auto schema = std::make_shared(std::move(fields)); auto batch = RecordBatch::Make(schema, kNumRows, columns); - ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); - for (auto _ : state) { ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); } - benchmark::DoNotOptimize(tensor); - state.SetItemsProcessed(state.iterations() * batch->num_rows() * batch->num_columns()); - state.SetBytesProcessed(state.iterations() * ty->bit_width() * batch->num_columns() * - batch->num_rows()); + state.SetItemsProcessed(state.iterations() * kNumRows * batch->num_columns()); + state.SetBytesProcessed(state.iterations() * ty->bit_width() * kNumRows * batch->num_columns()); +} + +void SetArgs(benchmark::internal::Benchmark* bench) { + BenchmarkSetArgsWithSizes(bench, {kL1Size, kL2Size}); } -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt8Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt16Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt32Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt64Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, Int8Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, Int16Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, Int32Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, Int64Type); -BENCHMARK_TEMPLATE(BatchToTensorSimple, HalfFloatType); -BENCHMARK_TEMPLATE(BatchToTensorSimple, FloatType); -BENCHMARK_TEMPLATE(BatchToTensorSimple, DoubleType); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt8Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt16Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt32Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt64Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int8Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int16Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int32Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, Int64Type)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, HalfFloatType)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, FloatType)->Apply(SetArgs); +BENCHMARK_TEMPLATE(BatchToTensorSimple, DoubleType)->Apply(SetArgs); } // namespace arrow From cff47a7728669c4323a72322f15525304100cac2 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Wed, 13 Mar 2024 14:43:04 +0100 Subject: [PATCH 05/14] Fix linter errors --- cpp/src/arrow/tensor_benchmark.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 7437eae09a08..8ebd5cc4235b 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -47,7 +47,8 @@ static void BatchToTensorSimple(benchmark::State& state) { ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); } state.SetItemsProcessed(state.iterations() * kNumRows * batch->num_columns()); - state.SetBytesProcessed(state.iterations() * ty->bit_width() * kNumRows * batch->num_columns()); + state.SetBytesProcessed(state.iterations() * ty->bit_width() * kNumRows * + batch->num_columns()); } void SetArgs(benchmark::internal::Benchmark* bench) { From 9e8a9c2d5b41ae7e8569da78bf781820966b6bb3 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Thu, 14 Mar 2024 15:17:52 +0100 Subject: [PATCH 06/14] Update benchmark arguments --- cpp/src/arrow/tensor_benchmark.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 8ebd5cc4235b..d1c881c3e568 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -30,7 +30,7 @@ static void BatchToTensorSimple(benchmark::State& state) { RegressionArgs args(state); std::shared_ptr ty = TypeTraits::type_singleton(); - const int64_t kNumRows = args.size * 8; + const int64_t kNumRows = args.size; arrow::random::RandomArrayGenerator gen_{42}; std::vector> fields = {}; @@ -52,7 +52,9 @@ static void BatchToTensorSimple(benchmark::State& state) { } void SetArgs(benchmark::internal::Benchmark* bench) { - BenchmarkSetArgsWithSizes(bench, {kL1Size, kL2Size}); + for (int64_t size : {kL1Size, kL2Size}) { + bench->Arg(size); + } } BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt8Type)->Apply(SetArgs); From bd993f19507217273d5eaec4787571e71af86f62 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Fri, 15 Mar 2024 13:31:52 +0100 Subject: [PATCH 07/14] Update size --- cpp/src/arrow/tensor_benchmark.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index d1c881c3e568..7f41a9050cde 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -28,9 +28,10 @@ namespace arrow { template static void BatchToTensorSimple(benchmark::State& state) { RegressionArgs args(state); + using CType = typename ValueType::c_type; std::shared_ptr ty = TypeTraits::type_singleton(); - const int64_t kNumRows = args.size; + const int64_t kNumRows = args.size / sizeof(CType); arrow::random::RandomArrayGenerator gen_{42}; std::vector> fields = {}; From 75817789c157046b5a8aaa541a1a8d404d98ab05 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Wed, 20 Mar 2024 15:13:32 +0100 Subject: [PATCH 08/14] Update cpp/src/arrow/tensor_benchmark.cc Co-authored-by: Joris Van den Bossche --- cpp/src/arrow/tensor_benchmark.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 7f41a9050cde..246261a8e4a3 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -48,7 +48,7 @@ static void BatchToTensorSimple(benchmark::State& state) { ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); } state.SetItemsProcessed(state.iterations() * kNumRows * batch->num_columns()); - state.SetBytesProcessed(state.iterations() * ty->bit_width() * kNumRows * + state.SetBytesProcessed(state.iterations() * ty->byte_width() * kNumRows * batch->num_columns()); } From c20fd1b21e0393b55e9d35fc06c323d2f767cf41 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 21 Mar 2024 14:37:05 +0100 Subject: [PATCH 09/14] Apply suggestions from code review Co-authored-by: Joris Van den Bossche --- cpp/src/arrow/tensor_benchmark.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 246261a8e4a3..dc194f91b3e8 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -27,11 +27,10 @@ namespace arrow { template static void BatchToTensorSimple(benchmark::State& state) { - RegressionArgs args(state); using CType = typename ValueType::c_type; std::shared_ptr ty = TypeTraits::type_singleton(); - const int64_t kNumRows = args.size / sizeof(CType); + const int64_t kNumRows = state.range(0) / sizeof(CType); arrow::random::RandomArrayGenerator gen_{42}; std::vector> fields = {}; From 014e3bd2a64b64d02c0c062eea1b4bc6618c2161 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Fri, 22 Mar 2024 12:13:39 +0100 Subject: [PATCH 10/14] Limit benchmarks to four integer types --- cpp/src/arrow/tensor_benchmark.cc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index dc194f91b3e8..b2c4f55c29c1 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -57,16 +57,9 @@ void SetArgs(benchmark::internal::Benchmark* bench) { } } -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt8Type)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt16Type)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt32Type)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, UInt64Type)->Apply(SetArgs); BENCHMARK_TEMPLATE(BatchToTensorSimple, Int8Type)->Apply(SetArgs); BENCHMARK_TEMPLATE(BatchToTensorSimple, Int16Type)->Apply(SetArgs); BENCHMARK_TEMPLATE(BatchToTensorSimple, Int32Type)->Apply(SetArgs); BENCHMARK_TEMPLATE(BatchToTensorSimple, Int64Type)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, HalfFloatType)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, FloatType)->Apply(SetArgs); -BENCHMARK_TEMPLATE(BatchToTensorSimple, DoubleType)->Apply(SetArgs); } // namespace arrow From 41d1218125e52adf995dd54d3bc5ee5fdff741bb Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Fri, 22 Mar 2024 13:11:39 +0100 Subject: [PATCH 11/14] Exercise different numbers of columns --- cpp/src/arrow/tensor_benchmark.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index b2c4f55c29c1..67bd1a8c8990 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -36,7 +36,8 @@ static void BatchToTensorSimple(benchmark::State& state) { std::vector> fields = {}; std::vector> columns = {}; - for (int i = 0; i < 100; ++i) { + const int NumCols = state.range(1); + for (int i = 0; i < NumCols; ++i) { fields.push_back(field("f" + std::to_string(i), ty)); columns.push_back(gen_.ArrayOf(ty, kNumRows)); } @@ -46,14 +47,15 @@ static void BatchToTensorSimple(benchmark::State& state) { for (auto _ : state) { ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); } - state.SetItemsProcessed(state.iterations() * kNumRows * batch->num_columns()); - state.SetBytesProcessed(state.iterations() * ty->byte_width() * kNumRows * - batch->num_columns()); + state.SetItemsProcessed(state.iterations() * kNumRows * NumCols); + state.SetBytesProcessed(state.iterations() * ty->byte_width() * kNumRows * NumCols); } void SetArgs(benchmark::internal::Benchmark* bench) { for (int64_t size : {kL1Size, kL2Size}) { - bench->Arg(size); + for (int number_of_columns : {3, 30, 300}) { + bench->Args({size, number_of_columns}); + } } } From 1d5badf08332f5b737dc4c8914c403d35656e368 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 22 Mar 2024 14:51:50 +0100 Subject: [PATCH 12/14] Update cpp/src/arrow/tensor_benchmark.cc Co-authored-by: Joris Van den Bossche --- cpp/src/arrow/tensor_benchmark.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 67bd1a8c8990..8cace41d6004 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -30,7 +30,8 @@ static void BatchToTensorSimple(benchmark::State& state) { using CType = typename ValueType::c_type; std::shared_ptr ty = TypeTraits::type_singleton(); - const int64_t kNumRows = state.range(0) / sizeof(CType); + const int64_t num_cols = state.range(1); + const int64_t num_rows = state.range(0) / num_cols / sizeof(CType); arrow::random::RandomArrayGenerator gen_{42}; std::vector> fields = {}; From 9b5eb40a06f6e728a1d1487ff26691938464a130 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Sun, 24 Mar 2024 07:45:36 +0100 Subject: [PATCH 13/14] Use num_cols and num_rows --- cpp/src/arrow/tensor_benchmark.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 8cace41d6004..23f09dbf5c5f 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -37,24 +37,23 @@ static void BatchToTensorSimple(benchmark::State& state) { std::vector> fields = {}; std::vector> columns = {}; - const int NumCols = state.range(1); - for (int i = 0; i < NumCols; ++i) { + for (int64_t i = 0; i < num_cols; ++i) { fields.push_back(field("f" + std::to_string(i), ty)); - columns.push_back(gen_.ArrayOf(ty, kNumRows)); + columns.push_back(gen_.ArrayOf(ty, num_rows)); } auto schema = std::make_shared(std::move(fields)); - auto batch = RecordBatch::Make(schema, kNumRows, columns); + auto batch = RecordBatch::Make(schema, num_rows, columns); for (auto _ : state) { ASSERT_OK_AND_ASSIGN(auto tensor, batch->ToTensor()); } - state.SetItemsProcessed(state.iterations() * kNumRows * NumCols); - state.SetBytesProcessed(state.iterations() * ty->byte_width() * kNumRows * NumCols); + state.SetItemsProcessed(state.iterations() * num_rows * num_cols); + state.SetBytesProcessed(state.iterations() * ty->byte_width() * num_rows * num_cols); } void SetArgs(benchmark::internal::Benchmark* bench) { for (int64_t size : {kL1Size, kL2Size}) { - for (int number_of_columns : {3, 30, 300}) { + for (int64_t number_of_columns : {3, 30, 300}) { bench->Args({size, number_of_columns}); } } From e53328214145982595c3adf3f582b7789a2fde54 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Mon, 25 Mar 2024 19:20:55 +0100 Subject: [PATCH 14/14] Add ArgNames --- cpp/src/arrow/tensor_benchmark.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/tensor_benchmark.cc b/cpp/src/arrow/tensor_benchmark.cc index 23f09dbf5c5f..91a9270ef347 100644 --- a/cpp/src/arrow/tensor_benchmark.cc +++ b/cpp/src/arrow/tensor_benchmark.cc @@ -53,8 +53,9 @@ static void BatchToTensorSimple(benchmark::State& state) { void SetArgs(benchmark::internal::Benchmark* bench) { for (int64_t size : {kL1Size, kL2Size}) { - for (int64_t number_of_columns : {3, 30, 300}) { - bench->Args({size, number_of_columns}); + for (int64_t num_columns : {3, 30, 300}) { + bench->Args({size, num_columns}); + bench->ArgNames({"size", "num_columns"}); } } }