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

Function BenchmarkNativeToValue

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

Source from the content-addressed store, hash-verified

1760}
1761
1762func BenchmarkNativeToValue(b *testing.B) {
1763 env := testNativeEnv(b)
1764 adapter := env.CELTypeAdapter()
1765
1766 nested := &TestNestedType{
1767 NestedListVal: []string{"a", "b", "c"},
1768 NestedMapVal: map[int64]bool{1: true},
1769 NestedCustomName: "test",
1770 }
1771 allTypes := &TestAllTypes{
1772 BoolVal: true,
1773 Int32Val: 10,
1774 Int64Val: 20,
1775 StringVal: "hello world",
1776 NestedVal: nested,
1777 ListVal: []*TestNestedType{nested},
1778 }
1779 allTypesSlice := []*TestAllTypes{allTypes, allTypes}
1780
1781 benchmarks := []struct {
1782 name string
1783 val any
1784 }{
1785 {name: "TestNestedType", val: nested},
1786 {name: "TestAllTypes", val: allTypes},
1787 {name: "SliceTestAllTypes", val: allTypesSlice},
1788 }
1789
1790 for _, bm := range benchmarks {
1791 b.Run(bm.name, func(b *testing.B) {
1792 b.ResetTimer()
1793 b.ReportAllocs()
1794 for i := 0; i < b.N; i++ {
1795 adapter.NativeToValue(bm.val)
1796 }
1797 })
1798 }
1799}
1800
1801func BenchmarkConvertToNative(b *testing.B) {
1802 env := testNativeEnv(b)

Callers

nothing calls this directly

Calls 3

CELTypeAdapterMethod · 0.80
testNativeEnvFunction · 0.70
NativeToValueMethod · 0.65

Tested by

no test coverage detected