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

Function BenchmarkDynamicDispatch

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

Source from the content-addressed store, hash-verified

3812}
3813
3814func BenchmarkDynamicDispatch(b *testing.B) {
3815 env := testEnv(b,
3816 HomogeneousAggregateLiterals(),
3817 Function("first",
3818 MemberOverload("first_list_int", []*Type{ListType(IntType)}, IntType,
3819 UnaryBinding(func(list ref.Val) ref.Val {
3820 l := list.(traits.Lister)
3821 if l.Size() == types.IntZero {
3822 return types.IntZero
3823 }
3824 return l.Get(types.IntZero)
3825 }),
3826 ),
3827 MemberOverload("first_list_double", []*Type{ListType(DoubleType)}, DoubleType,
3828 UnaryBinding(func(list ref.Val) ref.Val {
3829 l := list.(traits.Lister)
3830 if l.Size() == types.IntZero {
3831 return types.Double(0.0)
3832 }
3833 return l.Get(types.IntZero)
3834 }),
3835 ),
3836 MemberOverload("first_list_string", []*Type{ListType(StringType)}, StringType,
3837 UnaryBinding(func(list ref.Val) ref.Val {
3838 l := list.(traits.Lister)
3839 if l.Size() == types.IntZero {
3840 return types.String("")
3841 }
3842 return l.Get(types.IntZero)
3843 }),
3844 ),
3845 MemberOverload("first_list_list_string", []*Type{ListType(ListType(StringType))}, ListType(StringType),
3846 UnaryBinding(func(list ref.Val) ref.Val {
3847 l := list.(traits.Lister)
3848 if l.Size() == types.IntZero {
3849 return types.DefaultTypeAdapter.NativeToValue([]string{})
3850 }
3851 return l.Get(types.IntZero)
3852 }),
3853 ),
3854 ),
3855 )
3856 prg := compile(b, env, `
3857 [].first() == 0
3858 && [1, 2].first() == 1
3859 && [1.0, 2.0].first() == 1.0
3860 && ["hello", "world"].first() == "hello"
3861 && [["hello"], ["world", "!"]].first().first() == "hello"`)
3862 prgDyn := compile(b, env, `
3863 dyn([]).first() == 0
3864 && dyn([1, 2]).first() == 1
3865 && dyn([1.0, 2.0]).first() == 1.0
3866 && dyn(["hello", "world"]).first() == "hello"
3867 && dyn([["hello"], ["world", "!"]]).first().first() == "hello"`)
3868 b.ResetTimer()
3869 b.Run("DirectDispatch", func(b *testing.B) {
3870 for i := 0; i < b.N; i++ {
3871 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