|
17 | 17 | package commitment |
18 | 18 |
|
19 | 19 | import ( |
20 | | - "encoding/binary" |
21 | 20 | "testing" |
22 | 21 |
|
23 | 22 | "github.com/stretchr/testify/require" |
@@ -64,60 +63,6 @@ func BenchmarkBranchMerger_Merge(b *testing.B) { |
64 | 63 | } |
65 | 64 | } |
66 | 65 |
|
67 | | -func BenchmarkBranchData_ReplacePlainKeys(b *testing.B) { |
68 | | - row, bm := generateCellRow(b, 16) |
69 | | - |
70 | | - cells, am := unfoldBranchDataFromString(b, "86e586e5082035e72a782b51d9c98548467e3f868294d923cdbbdf4ce326c867bd972c4a2395090109203b51781a76dc87640aea038e3fdd8adca94049aaa436735b162881ec159f6fb408201aa2fa41b5fb019e8abf8fc32800805a2743cfa15373cf64ba16f4f70e683d8e0404a192d9050404f993d9050404e594d90508208642542ff3ce7d63b9703e85eb924ab3071aa39c25b1651c6dda4216387478f10404bd96d905") |
71 | | - for i, c := range cells { |
72 | | - if c == nil { |
73 | | - continue |
74 | | - } |
75 | | - if c.accountAddrLen > 0 { |
76 | | - offt, _ := binary.Uvarint(c.accountAddr[:c.accountAddrLen]) |
77 | | - b.Logf("%d apk %x, offt %d\n", i, c.accountAddr[:c.accountAddrLen], offt) |
78 | | - } |
79 | | - if c.storageAddrLen > 0 { |
80 | | - offt, _ := binary.Uvarint(c.storageAddr[:c.storageAddrLen]) |
81 | | - b.Logf("%d spk %x offt %d\n", i, c.storageAddr[:c.storageAddrLen], offt) |
82 | | - } |
83 | | - |
84 | | - } |
85 | | - _ = cells |
86 | | - _ = am |
87 | | - |
88 | | - cg := func(nibble int, skip bool) (*cell, error) { |
89 | | - return row[nibble], nil |
90 | | - } |
91 | | - |
92 | | - be := NewBranchEncoder(1024) |
93 | | - enc, _, err := be.EncodeBranch(bm, bm, bm, cg) |
94 | | - require.NoError(b, err) |
95 | | - |
96 | | - original := common.Copy(enc) |
97 | | - for b.Loop() { |
98 | | - target := make([]byte, 0, len(enc)) |
99 | | - oldKeys := make([][]byte, 0) |
100 | | - replaced, _, err := enc.ReplacePlainKeys(target, func(key []byte, isStorage bool) ([]byte, error) { |
101 | | - oldKeys = append(oldKeys, key) |
102 | | - if isStorage { |
103 | | - return key[:8], nil |
104 | | - } |
105 | | - return key[:4], nil |
106 | | - }) |
107 | | - require.NoError(b, err) |
108 | | - require.Lessf(b, len(replaced), len(enc), "replaced expected to be shorter than original enc") |
109 | | - |
110 | | - keyI := 0 |
111 | | - replacedBack, _, err := replaced.ReplacePlainKeys(nil, func(key []byte, isStorage bool) ([]byte, error) { |
112 | | - require.Equal(b, oldKeys[keyI][:4], key[:4]) |
113 | | - defer func() { keyI++ }() |
114 | | - return oldKeys[keyI], nil |
115 | | - }) |
116 | | - require.NoError(b, err) |
117 | | - require.EqualValues(b, original, replacedBack) |
118 | | - } |
119 | | -} |
120 | | - |
121 | 66 | // BenchmarkReplacePlainKeys_BufferReuse compares the old pattern (fresh make each call) |
122 | 67 | // against the new pattern (reused scratch buffer + bytes.Clone), matching what |
123 | 68 | // replaceShortenedKeysInBranch now does on AggregatorRoTx. |
|
0 commit comments