Skip to content

Commit 263795e

Browse files
authored
build: add benchmark build scaffolding (#825)
## Summary Adds an opt-in benchmark build path so future C++ microbenchmarks can live in-tree without affecting normal builds. Benchmarks stay disabled by default, and this PR keeps the executable intentionally small so reviewers can focus on CMake/Meson wiring and Google Benchmark integration. - Adds `ICEBERG_BUILD_BENCHMARKS` for CMake and a disabled-by-default `benchmarks` Meson feature. - Wires `src/iceberg/benchmark` into both build systems. - Adds Google Benchmark dependency setup for CMake and Meson. - Adds a tiny smoke benchmark so the new target is buildable in isolation. Part of #690. ## Stack This is PR 1 of 2. PR 2 adds the actual metrics evaluator benchmark cases on top of this scaffolding: timothyw553#1. ## Test Plan - [x] Configured benchmark-enabled CMake build with `-DICEBERG_BUILD_BENCHMARKS=ON`. - [x] Built `metrics_evaluator_benchmark` on this branch. - [x] Ran the smoke benchmark with `--benchmark_min_time=0.01s`. - [x] Re-ran the default build and test suite on the top of the stack: 18/18 tests passed. - [ ] Meson wiring is syntax-reviewed but not locally executed because `meson` is not installed in this shell. ## Verification Commands ```bash cmake -S . -B build-bench-stack -G Ninja \ -DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER \ -DCMAKE_IGNORE_PREFIX_PATH=/opt/homebrew/anaconda3 \ -DCMAKE_PREFIX_PATH='/opt/homebrew/opt/snappy;/opt/homebrew/opt/zstd' \ -DICEBERG_BUILD_BENCHMARKS=ON cmake --build build-bench-stack --target metrics_evaluator_benchmark build-bench-stack/src/iceberg/benchmark/metrics_evaluator_benchmark --benchmark_min_time=0.01s cmake --build build ctest --test-dir build --output-on-failure ```
1 parent 755799d commit 263795e

9 files changed

Lines changed: 160 additions & 0 deletions

File tree

.github/workflows/cpp-linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
7878
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
7979
-DICEBERG_BUILD_SQL_CATALOG=ON \
80+
-DICEBERG_BUILD_BENCHMARKS=ON \
8081
-DICEBERG_SQL_SQLITE=ON \
8182
-DICEBERG_SQL_POSTGRESQL=ON \
8283
-DICEBERG_SQL_MYSQL=ON

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
4040
option(ICEBERG_BUILD_STATIC "Build static library" ON)
4141
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
4242
option(ICEBERG_BUILD_TESTS "Build tests" ON)
43+
option(ICEBERG_BUILD_BENCHMARKS "Build benchmarks" OFF)
4344
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
4445
option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
4546
option(ICEBERG_BUILD_REST_INTEGRATION_TESTS "Build rest catalog integration tests" OFF)

meson.options

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ option(
5252
)
5353

5454
option('tests', type: 'feature', description: 'Build tests', value: 'enabled')
55+
56+
option(
57+
'benchmarks',
58+
type: 'feature',
59+
description: 'Build benchmarks',
60+
value: 'disabled',
61+
)

src/iceberg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,7 @@ endif()
365365
if(ICEBERG_BUILD_TESTS)
366366
add_subdirectory(test)
367367
endif()
368+
369+
if(ICEBERG_BUILD_BENCHMARKS)
370+
add_subdirectory(benchmark)
371+
endif()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
set(BENCHMARK_ENABLE_GTEST_TESTS
19+
OFF
20+
CACHE BOOL "" FORCE)
21+
set(BENCHMARK_ENABLE_INSTALL
22+
OFF
23+
CACHE BOOL "" FORCE)
24+
set(BENCHMARK_ENABLE_TESTING
25+
OFF
26+
CACHE BOOL "" FORCE)
27+
28+
fetchcontent_declare(google_benchmark
29+
GIT_REPOSITORY https://github.com/google/benchmark.git
30+
GIT_TAG a4cf155615c63e019ae549e31703bf367df5b471 # v1.8.4
31+
FIND_PACKAGE_ARGS
32+
NAMES
33+
benchmark
34+
CONFIG)
35+
fetchcontent_makeavailable(google_benchmark)
36+
37+
add_executable(benchmark_smoke benchmark_smoke.cc)
38+
target_link_libraries(benchmark_smoke
39+
PRIVATE "$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
40+
"$<IF:$<TARGET_EXISTS:benchmark::benchmark>,benchmark::benchmark,benchmark>"
41+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include <benchmark/benchmark.h>
21+
22+
namespace iceberg {
23+
namespace {
24+
25+
void BM_BenchmarkSmoke(benchmark::State& state) {
26+
while (state.KeepRunning()) {
27+
benchmark::DoNotOptimize(state.iterations());
28+
}
29+
30+
state.SetItemsProcessed(state.iterations());
31+
}
32+
33+
BENCHMARK(BM_BenchmarkSmoke);
34+
35+
} // namespace
36+
} // namespace iceberg
37+
38+
int main(int argc, char** argv) {
39+
benchmark::Initialize(&argc, argv);
40+
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
41+
return 1;
42+
}
43+
benchmark::RunSpecifiedBenchmarks();
44+
benchmark::Shutdown();
45+
return 0;
46+
}

src/iceberg/benchmark/meson.build

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
benchmark_dep = dependency('benchmark', required: true)
19+
20+
benchmark_smoke = executable(
21+
'benchmark_smoke',
22+
sources: files('benchmark_smoke.cc'),
23+
dependencies: [iceberg_dep, benchmark_dep],
24+
)
25+
26+
benchmark('benchmark_smoke', benchmark_smoke)

src/iceberg/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,7 @@ subdir('inspect')
337337
if get_option('tests').enabled()
338338
subdir('test')
339339
endif
340+
341+
if get_option('benchmarks').enabled()
342+
subdir('benchmark')
343+
endif

subprojects/google-benchmark.wrap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[wrap-file]
19+
directory = benchmark-1.8.4
20+
source_url = https://github.com/google/benchmark/archive/refs/tags/v1.8.4.tar.gz
21+
source_filename = benchmark-1.8.4.tar.gz
22+
source_hash = 3e7059b6b11fb1bbe28e33e02519398ca94c1818874ebed18e504dc6f709be45
23+
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/google-benchmark_1.8.4-5/benchmark-1.8.4.tar.gz
24+
patch_filename = google-benchmark_1.8.4-5_patch.zip
25+
patch_url = https://wrapdb.mesonbuild.com/v2/google-benchmark_1.8.4-5/get_patch
26+
patch_hash = 671ffed65f1e95e8c20edb7a06eb54476797e58169160b255f52dc71f4b83957
27+
wrapdb_version = 1.8.4-5
28+
29+
[provide]
30+
dependency_names = benchmark, benchmark_main

0 commit comments

Comments
 (0)