Skip to content

Commit

Permalink
Added and updated benchmarks
Browse files Browse the repository at this point in the history
Parsing entry bundles needs to be fast, so locked that in with a benchmark. While looking at other benchmarks, I noticed integrate wasn't using b.N, so wired that into the test instead of constant we already had to control the number of loops.
  • Loading branch information
mhutchinson committed Dec 9, 2024
1 parent 6106156 commit a0c938c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 17 additions & 0 deletions api/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/rand"
"crypto/sha256"
"fmt"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -144,3 +145,19 @@ func TestLeafBundle_UnmarshalText(t *testing.T) {
})
}
}

func BenchmarkLeafBundle_UnmarshalText(b *testing.B) {
bs := bytes.Buffer{}
for i := range 222 {
// Create leaves of different lengths for interest in the parsing / memory allocation
leafStr := strings.Repeat(fmt.Sprintf("Leaf %d", i), i%20)
_, _ = bs.Write(tessera.NewEntry([]byte(leafStr)).MarshalBundleData(uint64(i)))
}
rawBundle := bs.Bytes()
for i := 0; i < b.N; i++ {
tile := api.EntryBundle{}
if err := tile.UnmarshalText(rawBundle); err != nil {
b.Fatal(err)
}
}
}
3 changes: 1 addition & 2 deletions storage/internal/integrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ func BenchmarkIntegrate(b *testing.B) {
m := newMemTileStore[api.HashTile]()

chunkSize := 200
numChunks := 256
seq := uint64(0)
for chunk := 0; chunk < numChunks; chunk++ {
for chunk := 0; chunk < b.N; chunk++ {
oldSeq := seq
c := make([]SequencedEntry, chunkSize)
for i := range c {
Expand Down

0 comments on commit a0c938c

Please sign in to comment.