MCPcopy Create free account
hub / github.com/cel-expr/cel-go / BenchmarkDynamicDispatch

Function BenchmarkDynamicDispatch

cel/cel_test.go:4844–4910  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

4842}
4843
4844func BenchmarkDynamicDispatch(b *testing.B) {
4845 env := testEnv(b,
4846 HomogeneousAggregateLiterals(),
4847 Function("first",
4848 MemberOverload("first_list_int", []*Type{ListType(IntType)}, IntType,
4849 UnaryBinding(func(list ref.Val) ref.Val {
4850 l := list.(traits.Lister)
4851 if l.Size() == types.IntZero {
4852 return types.IntZero
4853 }
4854 return l.Get(types.IntZero)
4855 }),
4856 ),
4857 MemberOverload("first_list_double", []*Type{ListType(DoubleType)}, DoubleType,
4858 UnaryBinding(func(list ref.Val) ref.Val {
4859 l := list.(traits.Lister)
4860 if l.Size() == types.IntZero {
4861 return types.Double(0.0)
4862 }
4863 return l.Get(types.IntZero)
4864 }),
4865 ),
4866 MemberOverload("first_list_string", []*Type{ListType(StringType)}, StringType,
4867 UnaryBinding(func(list ref.Val) ref.Val {
4868 l := list.(traits.Lister)
4869 if l.Size() == types.IntZero {
4870 return types.String("")
4871 }
4872 return l.Get(types.IntZero)
4873 }),
4874 ),
4875 MemberOverload("first_list_list_string", []*Type{ListType(ListType(StringType))}, ListType(StringType),
4876 UnaryBinding(func(list ref.Val) ref.Val {
4877 l := list.(traits.Lister)
4878 if l.Size() == types.IntZero {
4879 return types.DefaultTypeAdapter.NativeToValue([]string{})
4880 }
4881 return l.Get(types.IntZero)
4882 }),
4883 ),
4884 ),
4885 )
4886 prg := compile(b, env, `
4887 [].first() == 0
4888 && [1, 2].first() == 1
4889 && [1.0, 2.0].first() == 1.0
4890 && ["hello", "world"].first() == "hello"
4891 && [["hello"], ["world", "!"]].first().first() == "hello"`)
4892 prgDyn := compile(b, env, `
4893 dyn([]).first() == 0
4894 && dyn([1, 2]).first() == 1
4895 && dyn([1.0, 2.0]).first() == 1.0
4896 && dyn(["hello", "world"]).first() == "hello"
4897 && dyn([["hello"], ["world", "!"]]).first().first() == "hello"`)
4898 b.ResetTimer()
4899 b.Run("DirectDispatch", func(b *testing.B) {
4900 for i := 0; i < b.N; i++ {
4901 prg.Eval(NoVars())

Callers

nothing calls this directly

Calls 13

DoubleTypeAlias · 0.92
StringTypeAlias · 0.92
NoVarsFunction · 0.85
testEnvFunction · 0.70
FunctionFunction · 0.70
MemberOverloadFunction · 0.70
UnaryBindingFunction · 0.70
compileFunction · 0.70
SizeMethod · 0.65
GetMethod · 0.65
NativeToValueMethod · 0.65

Tested by

no test coverage detected