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

Function BenchmarkConvertToNative

ext/native_test.go:1801–1839  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1799}
1800
1801func BenchmarkConvertToNative(b *testing.B) {
1802 env := testNativeEnv(b)
1803 adapter := env.CELTypeAdapter()
1804
1805 allTypes := &TestAllTypes{
1806 BoolVal: true,
1807 Int32Val: 10,
1808 Int64Val: 20,
1809 StringVal: "hello world",
1810 }
1811 celVal := adapter.NativeToValue(allTypes)
1812 targetType := reflect.TypeOf(&TestAllTypes{})
1813
1814 allTypesSlice := []*TestAllTypes{allTypes, allTypes}
1815 celSliceVal := adapter.NativeToValue(allTypesSlice)
1816 sliceTargetType := reflect.TypeOf([]*TestAllTypes{})
1817
1818 b.Run("TestAllTypes", func(b *testing.B) {
1819 b.ResetTimer()
1820 b.ReportAllocs()
1821 for i := 0; i < b.N; i++ {
1822 _, err := celVal.ConvertToNative(targetType)
1823 if err != nil {
1824 b.Fatalf("ConvertToNative failed: %v", err)
1825 }
1826 }
1827 })
1828
1829 b.Run("SliceTestAllTypes", func(b *testing.B) {
1830 b.ResetTimer()
1831 b.ReportAllocs()
1832 for i := 0; i < b.N; i++ {
1833 _, err := celSliceVal.ConvertToNative(sliceTargetType)
1834 if err != nil {
1835 b.Fatalf("ConvertToNative failed: %v", err)
1836 }
1837 }
1838 })
1839}

Callers

nothing calls this directly

Calls 4

CELTypeAdapterMethod · 0.80
testNativeEnvFunction · 0.70
NativeToValueMethod · 0.65
ConvertToNativeMethod · 0.65

Tested by

no test coverage detected