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

Function BenchmarkConvertToNative

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

Source from the content-addressed store, hash-verified

1574}
1575
1576func BenchmarkConvertToNative(b *testing.B) {
1577 env := testNativeEnv(b)
1578 adapter := env.CELTypeAdapter()
1579
1580 allTypes := &TestAllTypes{
1581 BoolVal: true,
1582 Int32Val: 10,
1583 Int64Val: 20,
1584 StringVal: "hello world",
1585 }
1586 celVal := adapter.NativeToValue(allTypes)
1587 targetType := reflect.TypeOf(&TestAllTypes{})
1588
1589 allTypesSlice := []*TestAllTypes{allTypes, allTypes}
1590 celSliceVal := adapter.NativeToValue(allTypesSlice)
1591 sliceTargetType := reflect.TypeOf([]*TestAllTypes{})
1592
1593 b.Run("TestAllTypes", func(b *testing.B) {
1594 b.ResetTimer()
1595 b.ReportAllocs()
1596 for i := 0; i < b.N; i++ {
1597 _, err := celVal.ConvertToNative(targetType)
1598 if err != nil {
1599 b.Fatalf("ConvertToNative failed: %v", err)
1600 }
1601 }
1602 })
1603
1604 b.Run("SliceTestAllTypes", func(b *testing.B) {
1605 b.ResetTimer()
1606 b.ReportAllocs()
1607 for i := 0; i < b.N; i++ {
1608 _, err := celSliceVal.ConvertToNative(sliceTargetType)
1609 if err != nil {
1610 b.Fatalf("ConvertToNative failed: %v", err)
1611 }
1612 }
1613 })
1614}

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