From 4701c12c850a66a02d82c9dd3dbbdc14b874e07b Mon Sep 17 00:00:00 2001 From: Jian Xiao Date: Tue, 18 Jun 2024 22:24:18 +0000 Subject: [PATCH] benchmark --- node/store.go | 6 +++--- node/store_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/node/store.go b/node/store.go index 5044410dea..4191e7dc42 100644 --- a/node/store.go +++ b/node/store.go @@ -334,7 +334,7 @@ func (s *Store) GetChunks(ctx context.Context, batchHeaderHash [32]byte, blobInd } log.Debug("Retrieved chunk", "blobKey", hexutil.Encode(blobKey), "length", len(data)) - chunks, err := decodeChunks(data) + chunks, err := DecodeChunks(data) if err != nil { return nil, false } @@ -377,8 +377,8 @@ func EncodeChunks(chunks [][]byte) ([]byte, error) { // Converts a flattened array of chunks into an array of its constituent chunks, // throwing an error in case the chunks were not serialized correctly // -// decodeChunks((len(chunks[0]), chunks[0], len(chunks[1]), chunks[1], ...)) = chunks -func decodeChunks(data []byte) ([][]byte, error) { +// DecodeChunks((len(chunks[0]), chunks[0], len(chunks[1]), chunks[1], ...)) = chunks +func DecodeChunks(data []byte) ([][]byte, error) { chunks := make([][]byte, 0) buf := data for len(buf) > 0 { diff --git a/node/store_test.go b/node/store_test.go index d35765175b..1f3c746ee0 100644 --- a/node/store_test.go +++ b/node/store_test.go @@ -286,3 +286,25 @@ func BenchmarkEncodeChunks(b *testing.B) { _, _ = node.EncodeChunks(sampleChunks[i%numSamples]) } } + +func BenchmarkDecocodeChunks(b *testing.B) { + numSamples := 32 + numChunks := 10 + chunkSize := 2 * 1024 + sampleChunks := make([][]byte, numSamples) + for n := 0; n < numSamples; n++ { + chunks := make([][]byte, numChunks) + for i := 0; i < numChunks; i++ { + chunk := make([]byte, chunkSize) + _, _ = cryptorand.Read(chunk) + chunks[i] = chunk + } + encoded, _ := node.EncodeChunks(chunks) + sampleChunks[n] = encoded + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, _ = node.DecodeChunks(sampleChunks[i%numSamples]) + } +}