This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new 0a9f45f0 chore: Add basic benchmark setup (#384)
0a9f45f0 is described below
commit 0a9f45f09d29a561eaaae4f4c8ee26f021624cd0
Author: Dewey Dunnington <[email protected]>
AuthorDate: Tue Feb 13 17:10:47 2024 -0400
chore: Add basic benchmark setup (#384)
---
.github/workflows/benchmarks.yaml | 52 +++++++++++++++++++++++++++++
.github/workflows/build-and-test.yaml | 5 +--
CMakeLists.txt | 59 ++++++++++++++-------------------
src/nanoarrow/schema_benchmark.cc | 31 +++++++++++++++++
thirdparty/benchmark/CMakeLists.txt | 27 +++++++++++++++
thirdparty/googletest/CMakeLists.txt | 34 +++++++++++++++++++
thirdparty/nlohmann_json/CMakeLists.txt | 24 ++++++++++++++
7 files changed, 193 insertions(+), 39 deletions(-)
diff --git a/.github/workflows/benchmarks.yaml
b/.github/workflows/benchmarks.yaml
new file mode 100644
index 00000000..3ebc8832
--- /dev/null
+++ b/.github/workflows/benchmarks.yaml
@@ -0,0 +1,52 @@
+# 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.
+
+name: benchmarks
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ branches:
+ - main
+ paths:
+ - 'CMakeLists.txt'
+ - '.github/workflows/benchmarks.yaml'
+ - 'src/**/*_benchmark.cc'
+
+jobs:
+ benchmarks:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Build nanoarrow
+ run: |
+ mkdir build && cd build
+ cmake .. -DNANOARROW_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release
+ cmake --build .
+
+ - name: Run benchmarks
+ run: |
+ cd build
+ for f in $(ls | grep -e "_benchmark"); do
+ echo "::group::$(basename ${f})"
+ ./${f}
+ done
diff --git a/.github/workflows/build-and-test.yaml
b/.github/workflows/build-and-test.yaml
index 851c7400..673b2293 100644
--- a/.github/workflows/build-and-test.yaml
+++ b/.github/workflows/build-and-test.yaml
@@ -47,10 +47,7 @@ jobs:
- {label: bundled-cpp-build, cmake_args: "-DNANOARROW_BUNDLE=ON
-DNANOARROW_BUNDLE_AS_CPP=ON"}
steps:
- - name: Checkout repo
- uses: actions/checkout@v3
- with:
- fetch-depth: 0
+ - uses: actions/checkout@v4
- name: Install dependencies
run: |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff8cfd36..327ba449 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,7 @@ set(NANOARROW_VERSION_MINOR "${nanoarrow_VERSION_MINOR}")
set(NANOARROW_VERSION_PATCH "${nanoarrow_VERSION_PATCH}")
option(NANOARROW_BUILD_TESTS "Build tests" OFF)
+option(NANOARROW_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(NANOARROW_BUILD_INTEGRATION_TESTS
"Build cross-implementation Arrow integration tests" OFF)
option(NANOARROW_BUNDLE "Create bundled nanoarrow.h and nanoarrow.c" OFF)
@@ -49,6 +50,12 @@ endif()
option(NANOARROW_CODE_COVERAGE "Enable coverage reporting" OFF)
add_library(coverage_config INTERFACE)
+# Avoids a warning about timestamps on downloaded files (prefer new policy
+# if available))
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23")
+ cmake_policy(SET CMP0135 NEW)
+endif()
+
configure_file(src/nanoarrow/nanoarrow_config.h.in
generated/nanoarrow_config.h)
if(NANOARROW_BUNDLE)
@@ -157,13 +164,7 @@ endif()
# Always build integration test if building tests
if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
- include(FetchContent)
-
- fetchcontent_declare(nlohmann_json
- URL
https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.zip
- URL_HASH
SHA256=95651d7d1fcf2e5c3163c3d37df6d6b3e9e5027299e6bd050d157322ceda9ac9
- )
- fetchcontent_makeavailable(nlohmann_json)
+ add_subdirectory("thirdparty/nlohmann_json")
add_library(nanoarrow_c_data_integration SHARED
src/nanoarrow/integration/c_data_integration.cc)
@@ -183,22 +184,6 @@ if(NANOARROW_BUILD_TESTS)
message(STATUS "Arrow version: ${ARROW_VERSION}")
message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}")
- # Arrow >= 10.0.0 requires C++17; GTest requires C++11.
- # Leave the option open to use an older version of Arrow
- # to make it easier to test on old Linux (e.g., Centos7)
- if(${ARROW_VERSION} VERSION_GREATER_EQUAL "10.0.0")
- set(CMAKE_CXX_STANDARD 17)
- else()
- set(CMAKE_CXX_STANDARD 11)
- endif()
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
-
- # Avoids a warning about timestamps on downloaded files (prefer new policy
- # if available))
- if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23")
- cmake_policy(SET CMP0135 NEW)
- endif()
-
# Give caller the option to link a static version of Arrow C++
if(NANOARROW_ARROW_STATIC)
set(NANOARROW_ARROW_TARGET arrow_static)
@@ -206,21 +191,17 @@ if(NANOARROW_BUILD_TESTS)
set(NANOARROW_ARROW_TARGET arrow_shared)
endif()
- # Use an old version of googletest if we have to to support gcc 4.8
- if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION
- VERSION_GREATER_EQUAL "5.0.0")
- fetchcontent_declare(googletest
- URL
https://github.com/google/googletest/archive/release-1.11.0.zip
- URL_HASH
SHA256=353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a
- )
+ # Arrow >= 10.0.0 requires C++17; GTest requires C++11.
+ # Leave the option open to use an older version of Arrow
+ # to make it easier to test on old Linux (e.g., Centos7)
+ if(${ARROW_VERSION} VERSION_GREATER_EQUAL "10.0.0")
+ set(CMAKE_CXX_STANDARD 17)
else()
- fetchcontent_declare(googletest
- URL
https://github.com/google/googletest/archive/release-1.10.0.zip
- URL_HASH
SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
- )
+ set(CMAKE_CXX_STANDARD 11)
endif()
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
- fetchcontent_makeavailable(googletest)
+ add_subdirectory("thirdparty/googletest")
add_executable(utils_test src/nanoarrow/utils_test.cc)
add_executable(buffer_test src/nanoarrow/buffer_test.cc)
@@ -277,3 +258,11 @@ if(NANOARROW_BUILD_TESTS)
gtest_discover_tests(nanoarrow_testing_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(c_data_integration_test DISCOVERY_TIMEOUT 10)
endif()
+
+if(NANOARROW_BUILD_BENCHMARKS)
+ add_subdirectory("thirdparty/benchmark")
+
+ add_executable(schema_benchmark src/nanoarrow/schema_benchmark.cc)
+ target_link_libraries(schema_benchmark PRIVATE nanoarrow
benchmark::benchmark_main)
+
+endif()
diff --git a/src/nanoarrow/schema_benchmark.cc
b/src/nanoarrow/schema_benchmark.cc
new file mode 100644
index 00000000..10b45841
--- /dev/null
+++ b/src/nanoarrow/schema_benchmark.cc
@@ -0,0 +1,31 @@
+// 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 "nanoarrow.h"
+
+static void BM_SchemaInit(benchmark::State& state) {
+ struct ArrowSchema schema;
+
+ for (auto _ : state) {
+ ArrowSchemaInit(&schema);
+ }
+}
+
+// Register the function as a benchmark
+BENCHMARK(BM_SchemaInit);
diff --git a/thirdparty/benchmark/CMakeLists.txt
b/thirdparty/benchmark/CMakeLists.txt
new file mode 100644
index 00000000..ae52bf90
--- /dev/null
+++ b/thirdparty/benchmark/CMakeLists.txt
@@ -0,0 +1,27 @@
+# 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(FetchContent)
+
+set(BENCHMARK_ENABLE_TESTING OFF)
+
+fetchcontent_declare(benchmark
+ URL
https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
+ URL_HASH
SHA256=abfc22e33e3594d0edf8eaddaf4d84a2ffc491ad74b6a7edc6e7a608f690e691
+)
+
+fetchcontent_makeavailable(benchmark)
diff --git a/thirdparty/googletest/CMakeLists.txt
b/thirdparty/googletest/CMakeLists.txt
new file mode 100644
index 00000000..b32d52e5
--- /dev/null
+++ b/thirdparty/googletest/CMakeLists.txt
@@ -0,0 +1,34 @@
+# 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(FetchContent)
+
+# Use an old version of googletest if we have to to support gcc 4.8
+if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION
+ VERSION_GREATER_EQUAL "5.0.0")
+ fetchcontent_declare(googletest
+ URL
https://github.com/google/googletest/archive/release-1.11.0.zip
+ URL_HASH
SHA256=353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a
+ )
+else()
+ fetchcontent_declare(googletest
+ URL
https://github.com/google/googletest/archive/release-1.10.0.zip
+ URL_HASH
SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
+ )
+endif()
+
+fetchcontent_makeavailable(googletest)
diff --git a/thirdparty/nlohmann_json/CMakeLists.txt
b/thirdparty/nlohmann_json/CMakeLists.txt
new file mode 100644
index 00000000..a55b5574
--- /dev/null
+++ b/thirdparty/nlohmann_json/CMakeLists.txt
@@ -0,0 +1,24 @@
+# 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(FetchContent)
+
+fetchcontent_declare(nlohmann_json
+ URL
https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.zip
+ URL_HASH
SHA256=95651d7d1fcf2e5c3163c3d37df6d6b3e9e5027299e6bd050d157322ceda9ac9
+)
+fetchcontent_makeavailable(nlohmann_json)