1
0
Fork 0
mirror of https://github.com/vbatts/merkle.git synced 2024-12-02 19:15:39 +00:00

stream: adding a benchmark

Based on stdlib's `sha256`. Initial output:
BenchmarkHash8Bytes       100000             20387 ns/op           0.39 MB/s
BenchmarkHash1K    50000             25876 ns/op          39.57 MB/s
BenchmarkHash8K    50000             38836 ns/op         210.94 MB/s
This commit is contained in:
Vincent Batts 2015-08-16 14:49:58 -04:00
parent 71d35fdc80
commit 08e311195d

View file

@ -136,3 +136,28 @@ func TestMerkleHashWriter(t *testing.T) {
}
}
var bench = NewHash(DefaultHashMaker, 8192)
var buf = make([]byte, 8192)
func benchmarkSize(b *testing.B, size int) {
b.SetBytes(int64(size))
sum := make([]byte, bench.Size())
for i := 0; i < b.N; i++ {
bench.Reset()
bench.Write(buf[:size])
bench.Sum(sum[:0])
}
}
func BenchmarkHash8Bytes(b *testing.B) {
benchmarkSize(b, 8)
}
func BenchmarkHash1K(b *testing.B) {
benchmarkSize(b, 1024)
}
func BenchmarkHash8K(b *testing.B) {
benchmarkSize(b, 8192)
}