Skip to content

Commit 13d4108

Browse files
committed
[C++][Gandiva] Add Benchmark
1 parent e27b758 commit 13d4108

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

cpp/src/gandiva/tests/micro_benchmarks.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,29 @@ static void TimedTestExprCompilation(benchmark::State& state) {
450450
}
451451
}
452452

453+
static void TimedTestNonBitcodeExprCompilation(benchmark::State& state, bool use_cache) {
454+
int32_t iteration = 0;
455+
for (auto _ : state) {
456+
// schema for input fields
457+
double literal_value = use_cache ? 1.0 : static_cast<double>(iteration);
458+
auto seed = TreeExprBuilder::MakeLiteral(literal_value);
459+
auto schema = arrow::schema({});
460+
461+
// output field
462+
auto field_sin = field("c1", float64());
463+
464+
// seed is different for each iteration so that cache won't be hit
465+
auto sin_func = TreeExprBuilder::MakeFunction("sin", {seed}, float64());
466+
467+
auto expr_0 = TreeExprBuilder::MakeExpression(sin_func, field_sin);
468+
469+
std::shared_ptr<Projector> projector;
470+
ASSERT_OK(Projector::Make(schema, {expr_0}, TestConfiguration(), &projector));
471+
472+
++iteration;
473+
}
474+
}
475+
453476
static void DecimalAdd2Fast(benchmark::State& state) {
454477
// use lesser precision to test the fast-path
455478
DoDecimalAdd2(state, DecimalTypeUtil::kMaxPrecision - 6, 18);
@@ -490,6 +513,16 @@ static void DecimalAdd3Large(benchmark::State& state) {
490513
DoDecimalAdd3(state, DecimalTypeUtil::kMaxPrecision, 18, true);
491514
}
492515

516+
static void TimedTestNonBitcodeExprCompilationNoCache(benchmark::State& state) {
517+
TimedTestNonBitcodeExprCompilation(state, false);
518+
}
519+
520+
static void TimedTestNonBitcodeExprCompilationWithCache(benchmark::State& state) {
521+
TimedTestNonBitcodeExprCompilation(state, true);
522+
}
523+
524+
BENCHMARK(TimedTestNonBitcodeExprCompilationNoCache)->Unit(benchmark::kMicrosecond);
525+
BENCHMARK(TimedTestNonBitcodeExprCompilationWithCache)->Unit(benchmark::kMicrosecond);
493526
BENCHMARK(TimedTestExprCompilation)->Unit(benchmark::kMicrosecond);
494527
BENCHMARK(TimedTestAdd3)->Unit(benchmark::kMicrosecond);
495528
BENCHMARK(TimedTestBigNested)->Unit(benchmark::kMicrosecond);

0 commit comments

Comments
 (0)