-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add benchmarks to share encoding and decoding (#83)
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package shares_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/celestiaorg/go-square/internal/test" | ||
"github.com/celestiaorg/go-square/shares" | ||
) | ||
|
||
func BenchmarkBlobsToShares(b *testing.B) { | ||
sizes := []int{256, 256 * 8, 256 * 64} | ||
numBlobs := []int{1, 8, 64} | ||
for _, size := range sizes { | ||
for _, numBlobs := range numBlobs { | ||
b.Run(fmt.Sprintf("ShareEncoding%dBlobs%dBytes", numBlobs, size), func(b *testing.B) { | ||
b.ReportAllocs() | ||
blobs := test.GenerateBlobs(test.Repeat(size, numBlobs)...) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
// Convert blob to shares | ||
_, err := shares.SplitBlobs(blobs...) | ||
if err != nil { | ||
b.Fatal("Failed to split blob into shares:", err) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkSharesToBlobs(b *testing.B) { | ||
sizes := []int{256, 256 * 8, 256 * 64} | ||
numBlobs := []int{1, 8, 64} | ||
for _, size := range sizes { | ||
for _, numBlobs := range numBlobs { | ||
b.Run(fmt.Sprintf("ShareDecoding%dBlobs%dBytes", numBlobs, size), func(b *testing.B) { | ||
b.ReportAllocs() | ||
blobs := test.GenerateBlobs(test.Repeat(size, numBlobs)...) | ||
s, err := shares.SplitBlobs(blobs...) | ||
if err != nil { | ||
b.Fatal("Failed to split blob into shares:", err) | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
// Convert shares back to blob | ||
_, err := shares.ParseBlobs(s) | ||
if err != nil { | ||
b.Fatal("Failed to reconstruct blob from shares:", err) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} |