Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
52 lines
1,023 B
Go
52 lines
1,023 B
Go
package tmhash
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha256"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
var sink any
|
|
|
|
var manySlices = []struct {
|
|
name string
|
|
in [][]byte
|
|
want [32]byte
|
|
}{
|
|
{
|
|
name: "all empty",
|
|
in: [][]byte{[]byte(""), []byte("")},
|
|
want: sha256.Sum256(nil),
|
|
},
|
|
{
|
|
name: "ax6",
|
|
in: [][]byte{[]byte("aaaa"), []byte("😎"), []byte("aaaa")},
|
|
want: sha256.Sum256([]byte("aaaa😎aaaa")),
|
|
},
|
|
{
|
|
name: "composite joined",
|
|
in: [][]byte{bytes.Repeat([]byte("a"), 1<<10), []byte("AA"), bytes.Repeat([]byte("z"), 100)},
|
|
want: sha256.Sum256([]byte(strings.Repeat("a", 1<<10) + "AA" + strings.Repeat("z", 100))),
|
|
},
|
|
}
|
|
|
|
func BenchmarkSHA256Many(b *testing.B) {
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
for _, tt := range manySlices {
|
|
got := SumMany(tt.in[0], tt.in[1:]...)
|
|
if !bytes.Equal(got, tt.want[:]) {
|
|
b.Fatalf("Outward checksum mismatch for %q\n\tGot: %x\n\tWant: %x", tt.name, got, tt.want)
|
|
}
|
|
sink = got
|
|
}
|
|
}
|
|
|
|
if sink == nil {
|
|
b.Fatal("Benchmark did not run!")
|
|
}
|
|
|
|
sink = nil
|
|
}
|