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

Function BenchmarkDynamicDispatch

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

Source from the content-addressed store, hash-verified

4077}
4078
4079func BenchmarkDynamicDispatch(b *testing.B) {
4080 env := testEnv(b,
4081 HomogeneousAggregateLiterals(),
4082 Function("first",
4083 MemberOverload("first_list_int", []*Type{ListType(IntType)}, IntType,
4084 UnaryBinding(func(list ref.Val) ref.Val {
4085 l := list.(traits.Lister)
4086 if l.Size() == types.IntZero {
4087 return types.IntZero
4088 }
4089 return l.Get(types.IntZero)
4090 }),
4091 ),
4092 MemberOverload("first_list_double", []*Type{ListType(DoubleType)}, DoubleType,
4093 UnaryBinding(func(list ref.Val) ref.Val {
4094 l := list.(traits.Lister)
4095 if l.Size() == types.IntZero {
4096 return types.Double(0.0)
4097 }
4098 return l.Get(types.IntZero)
4099 }),
4100 ),
4101 MemberOverload("first_list_string", []*Type{ListType(StringType)}, StringType,
4102 UnaryBinding(func(list ref.Val) ref.Val {
4103 l := list.(traits.Lister)
4104 if l.Size() == types.IntZero {
4105 return types.String("")
4106 }
4107 return l.Get(types.IntZero)
4108 }),
4109 ),
4110 MemberOverload("first_list_list_string", []*Type{ListType(ListType(StringType))}, ListType(StringType),
4111 UnaryBinding(func(list ref.Val) ref.Val {
4112 l := list.(traits.Lister)
4113 if l.Size() == types.IntZero {
4114 return types.DefaultTypeAdapter.NativeToValue([]string{})
4115 }
4116 return l.Get(types.IntZero)
4117 }),
4118 ),
4119 ),
4120 )
4121 prg := compile(b, env, `
4122 [].first() == 0
4123 && [1, 2].first() == 1
4124 && [1.0, 2.0].first() == 1.0
4125 && ["hello", "world"].first() == "hello"
4126 && [["hello"], ["world", "!"]].first().first() == "hello"`)
4127 prgDyn := compile(b, env, `
4128 dyn([]).first() == 0
4129 && dyn([1, 2]).first() == 1
4130 && dyn([1.0, 2.0]).first() == 1.0
4131 && dyn(["hello", "world"]).first() == "hello"
4132 && dyn([["hello"], ["world", "!"]]).first().first() == "hello"`)
4133 b.ResetTimer()
4134 b.Run("DirectDispatch", func(b *testing.B) {
4135 for i := 0; i < b.N; i++ {
4136 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