MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / BenchmarkState

Class BenchmarkState

codelab/network_functions_test.cc:197–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195 info) { return info.param.name; });
196
197class BenchmarkState {
198 public:
199 static absl::StatusOr<BenchmarkState> Create(bool optimize) {
200 CEL_ASSIGN_OR_RETURN(
201 auto compiler_builder,
202 cel::NewCompilerBuilder(cel::GetMinimalDescriptorPool()));
203 CEL_RETURN_IF_ERROR(
204 compiler_builder->AddLibrary(cel::StandardCompilerLibrary()));
205 CEL_RETURN_IF_ERROR(
206 compiler_builder->AddLibrary(NetworkFunctionsCompilerLibrary()));
207 compiler_builder->GetCheckerBuilder()
208 .AddVariable(MakeVariableDecl("ip", cel::StringType()))
209 .IgnoreError();
210
211 CEL_ASSIGN_OR_RETURN(auto compiler, compiler_builder->Build());
212
213 RuntimeOptions runtime_options;
214 CEL_ASSIGN_OR_RETURN(auto runtime_builder,
215 CreateStandardRuntimeBuilder(
216 cel::GetMinimalDescriptorPool(), runtime_options));
217 CEL_RETURN_IF_ERROR(
218 RegisterNetworkTypes(runtime_builder.type_registry(), runtime_options));
219 CEL_RETURN_IF_ERROR(RegisterNetworkFunctions(
220 runtime_builder.function_registry(), runtime_options));
221
222 if (optimize) {
223 CEL_RETURN_IF_ERROR(
224 cel::extensions::EnableConstantFolding(runtime_builder));
225 }
226 CEL_ASSIGN_OR_RETURN(auto runtime, std::move(runtime_builder).Build());
227 return BenchmarkState(std::move(compiler), std::move(runtime));
228 }
229
230 absl::StatusOr<std::unique_ptr<Program>> MakeProgram(absl::string_view expr) {
231 CEL_ASSIGN_OR_RETURN(auto result, compiler_->Compile(expr));
232 if (!result.IsValid()) {
233 return absl::InvalidArgumentError(result.FormatError());
234 }
235 CEL_ASSIGN_OR_RETURN(auto ast, result.ReleaseAst());
236 return runtime_->CreateProgram(std::move(ast));
237 }
238
239 private:
240 BenchmarkState(std::unique_ptr<Compiler> c, std::unique_ptr<const Runtime> r)
241 : compiler_(std::move(c)), runtime_(std::move(r)) {}
242
243 std::unique_ptr<Compiler> compiler_;
244 std::unique_ptr<const Runtime> runtime_;
245 std::unique_ptr<google::protobuf::Arena> constants_;
246};
247
248void BM_ParseAddress(benchmark::State& state) {
249 bool optimize = state.range(0);

Callers 1

CreateMethod · 0.85

Calls

no outgoing calls

Tested by 1

CreateMethod · 0.68