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

Function BenchmarkDynamicDispatch

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

Source from the content-addressed store, hash-verified

3706}
3707
3708func BenchmarkDynamicDispatch(b *testing.B) {
3709 env := testEnv(b,
3710 HomogeneousAggregateLiterals(),
3711 Function("first",
3712 MemberOverload("first_list_int", []*Type{ListType(IntType)}, IntType,
3713 UnaryBinding(func(list ref.Val) ref.Val {
3714 l := list.(traits.Lister)
3715 if l.Size() == types.IntZero {
3716 return types.IntZero
3717 }
3718 return l.Get(types.IntZero)
3719 }),
3720 ),
3721 MemberOverload("first_list_double", []*Type{ListType(DoubleType)}, DoubleType,
3722 UnaryBinding(func(list ref.Val) ref.Val {
3723 l := list.(traits.Lister)
3724 if l.Size() == types.IntZero {
3725 return types.Double(0.0)
3726 }
3727 return l.Get(types.IntZero)
3728 }),
3729 ),
3730 MemberOverload("first_list_string", []*Type{ListType(StringType)}, StringType,
3731 UnaryBinding(func(list ref.Val) ref.Val {
3732 l := list.(traits.Lister)
3733 if l.Size() == types.IntZero {
3734 return types.String("")
3735 }
3736 return l.Get(types.IntZero)
3737 }),
3738 ),
3739 MemberOverload("first_list_list_string", []*Type{ListType(ListType(StringType))}, ListType(StringType),
3740 UnaryBinding(func(list ref.Val) ref.Val {
3741 l := list.(traits.Lister)
3742 if l.Size() == types.IntZero {
3743 return types.DefaultTypeAdapter.NativeToValue([]string{})
3744 }
3745 return l.Get(types.IntZero)
3746 }),
3747 ),
3748 ),
3749 )
3750 prg := compile(b, env, `
3751 [].first() == 0
3752 && [1, 2].first() == 1
3753 && [1.0, 2.0].first() == 1.0
3754 && ["hello", "world"].first() == "hello"
3755 && [["hello"], ["world", "!"]].first().first() == "hello"`)
3756 prgDyn := compile(b, env, `
3757 dyn([]).first() == 0
3758 && dyn([1, 2]).first() == 1
3759 && dyn([1.0, 2.0]).first() == 1.0
3760 && dyn(["hello", "world"]).first() == "hello"
3761 && dyn([["hello"], ["world", "!"]]).first().first() == "hello"`)
3762 b.ResetTimer()
3763 b.Run("DirectDispatch", func(b *testing.B) {
3764 for i := 0; i < b.N; i++ {
3765 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