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

Function BenchmarkDynamicDispatch

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

Source from the content-addressed store, hash-verified

4019}
4020
4021func BenchmarkDynamicDispatch(b *testing.B) {
4022 env := testEnv(b,
4023 HomogeneousAggregateLiterals(),
4024 Function("first",
4025 MemberOverload("first_list_int", []*Type{ListType(IntType)}, IntType,
4026 UnaryBinding(func(list ref.Val) ref.Val {
4027 l := list.(traits.Lister)
4028 if l.Size() == types.IntZero {
4029 return types.IntZero
4030 }
4031 return l.Get(types.IntZero)
4032 }),
4033 ),
4034 MemberOverload("first_list_double", []*Type{ListType(DoubleType)}, DoubleType,
4035 UnaryBinding(func(list ref.Val) ref.Val {
4036 l := list.(traits.Lister)
4037 if l.Size() == types.IntZero {
4038 return types.Double(0.0)
4039 }
4040 return l.Get(types.IntZero)
4041 }),
4042 ),
4043 MemberOverload("first_list_string", []*Type{ListType(StringType)}, StringType,
4044 UnaryBinding(func(list ref.Val) ref.Val {
4045 l := list.(traits.Lister)
4046 if l.Size() == types.IntZero {
4047 return types.String("")
4048 }
4049 return l.Get(types.IntZero)
4050 }),
4051 ),
4052 MemberOverload("first_list_list_string", []*Type{ListType(ListType(StringType))}, ListType(StringType),
4053 UnaryBinding(func(list ref.Val) ref.Val {
4054 l := list.(traits.Lister)
4055 if l.Size() == types.IntZero {
4056 return types.DefaultTypeAdapter.NativeToValue([]string{})
4057 }
4058 return l.Get(types.IntZero)
4059 }),
4060 ),
4061 ),
4062 )
4063 prg := compile(b, env, `
4064 [].first() == 0
4065 && [1, 2].first() == 1
4066 && [1.0, 2.0].first() == 1.0
4067 && ["hello", "world"].first() == "hello"
4068 && [["hello"], ["world", "!"]].first().first() == "hello"`)
4069 prgDyn := compile(b, env, `
4070 dyn([]).first() == 0
4071 && dyn([1, 2]).first() == 1
4072 && dyn([1.0, 2.0]).first() == 1.0
4073 && dyn(["hello", "world"]).first() == "hello"
4074 && dyn([["hello"], ["world", "!"]]).first().first() == "hello"`)
4075 b.ResetTimer()
4076 b.Run("DirectDispatch", func(b *testing.B) {
4077 for i := 0; i < b.N; i++ {
4078 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