Skip to content

Commit 97850bb

Browse files
committed
Fix benchmark test and remove from standard test suite.
1 parent e9c172d commit 97850bb

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

cpp/src/gandiva/precompiled/CMakeLists.txt

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,28 @@ add_gandiva_test(precompiled-test
8585
ARROW_STATIC
8686
GANDIVA_STATIC)
8787

88-
# microbenchmark (built as a gandiva test so it links the precompiled sources
89-
# directly; run on demand via the gandiva-precompiled-benchmark binary)
90-
add_gandiva_test(precompiled-benchmark
91-
SOURCES
92-
../context_helper.cc
93-
string_ops_benchmark.cc
94-
string_ops.cc
95-
EXTRA_INCLUDES
96-
${CMAKE_SOURCE_DIR}/src
97-
EXTRA_LINK_LIBS
98-
Boost::headers
99-
DEFINITIONS
100-
GANDIVA_UNIT_TEST=1
101-
ARROW_STATIC
102-
GANDIVA_STATIC)
88+
# REPLACE microbenchmark. Built on demand only -- it is a plain executable, NOT
89+
# registered as a ctest test, so it never runs in check-in/ctest runs. Build and
90+
# run it explicitly via the gandiva-precompiled-benchmark binary. It compiles the
91+
# precompiled sources locally (with GANDIVA_UNIT_TEST=1) so the functions are
92+
# directly callable, mirroring how the precompiled-test target links.
93+
if(ARROW_BUILD_TESTS)
94+
if(ARROW_TEST_LINKAGE STREQUAL "static")
95+
set(GANDIVA_BENCHMARK_LINK_LIBS ${GANDIVA_STATIC_TEST_LINK_LIBS})
96+
else()
97+
set(GANDIVA_BENCHMARK_LINK_LIBS ${GANDIVA_SHARED_TEST_LINK_LIBS})
98+
endif()
99+
add_executable(gandiva-precompiled-benchmark string_ops_benchmark.cc string_ops.cc
100+
../context_helper.cc)
101+
target_link_libraries(gandiva-precompiled-benchmark
102+
PRIVATE ${ARROW_GTEST_GTEST_HEADERS}
103+
${GANDIVA_BENCHMARK_LINK_LIBS} Boost::headers)
104+
target_include_directories(gandiva-precompiled-benchmark SYSTEM
105+
PUBLIC ${CMAKE_SOURCE_DIR}/src)
106+
target_compile_definitions(gandiva-precompiled-benchmark
107+
PRIVATE GANDIVA_UNIT_TEST=1 ARROW_STATIC GANDIVA_STATIC)
108+
if(ARROW_TEST_LINKAGE STREQUAL "static")
109+
# libLLVM*.a needs the executable to export the ORC EH-frame wrappers.
110+
set_target_properties(gandiva-precompiled-benchmark PROPERTIES ENABLE_EXPORTS TRUE)
111+
endif()
112+
endif()

cpp/src/gandiva/precompiled/string_ops_benchmark.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ TEST(StringOpsBenchmark, Replace) {
141141
ctx.Reset();
142142
};
143143

144-
// Warm up (and verify both produce the same length / no error).
145-
run_new();
146-
ASSERT_FALSE(ctx.has_error());
147-
run_old();
148-
ASSERT_FALSE(ctx.has_error());
144+
// Warm up and verify correctness. Check has_error()/out_len BEFORE Reset(),
145+
// since Reset() clears the error and the timed lambdas reset internally.
146+
int32_t new_len = 0;
147+
replace_utf8_utf8_utf8(ctx_ptr, tp, tlen, fp, flen, op, olen, &new_len);
148+
ASSERT_FALSE(ctx.has_error()) << c.name << ": " << ctx.get_error();
149+
ctx.Reset();
150+
int32_t old_len = 0;
151+
replace_with_max_len_utf8_utf8_utf8(ctx_ptr, tp, tlen, fp, flen, op, olen,
152+
out_capacity, &old_len);
153+
ASSERT_FALSE(ctx.has_error()) << c.name << ": " << ctx.get_error();
154+
ctx.Reset();
155+
ASSERT_EQ(new_len, old_len) << c.name << ": new/old output lengths differ";
149156

150157
double new_ns = TimeNsPerCall(run_new, c.iters);
151158
double old_ns = TimeNsPerCall(run_old, c.iters);

0 commit comments

Comments
 (0)