Skip to content

Commit

Permalink
benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Jun 18, 2024
1 parent aedc964 commit 4701c12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions node/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 4701c12

Please sign in to comment.