| 103 | } |
| 104 | |
| 105 | void ExpressionBenchmarkBuilder::registerBenchmarks() { |
| 106 | ensureInputVectors(); |
| 107 | // Generate input vectors if needed. |
| 108 | for (auto& [setName, benchmarkSet] : benchmarkSets_) { |
| 109 | for (auto& [exprName, exprSet] : benchmarkSet.expressions_) { |
| 110 | auto name = fmt::format("{}##{}", setName, exprName); |
| 111 | auto& inputVector = benchmarkSet.inputRowVector_; |
| 112 | auto times = benchmarkSet.iterations_; |
| 113 | // The compiler does not allow capturing exprSet int the lambda. |
| 114 | auto& exprSetLocal = exprSet; |
| 115 | folly::addBenchmark( |
| 116 | __FILE__, name, [this, &inputVector, &exprSetLocal, times]() { |
| 117 | int cnt = 0; |
| 118 | folly::BenchmarkSuspender suspender; |
| 119 | // TODO: shall we cache those. |
| 120 | exec::EvalCtx evalCtx( |
| 121 | &this->execCtx_, &exprSetLocal, inputVector.get()); |
| 122 | SelectivityVector rows(inputVector->size()); |
| 123 | suspender.dismiss(); |
| 124 | |
| 125 | std::vector<VectorPtr> results(1); |
| 126 | for (auto i = 0; i < times; i++) { |
| 127 | exprSetLocal.eval(rows, evalCtx, results); |
| 128 | |
| 129 | // TODO: add flag to enable/disable flattening. |
| 130 | BaseVector::flattenVector(results[0]); |
| 131 | |
| 132 | // TODO: add flag to enable/disable reuse. |
| 133 | results[0]->prepareForReuse(); |
| 134 | |
| 135 | cnt += results[0]->size(); |
| 136 | } |
| 137 | folly::doNotOptimizeAway(cnt); |
| 138 | return 1; |
| 139 | }); |
| 140 | } |
| 141 | BENCHMARK_DRAW_LINE(); |
| 142 | BENCHMARK_DRAW_LINE(); |
| 143 | } |
| 144 | } |
| 145 | } // namespace bytedance::bolt |