From eaeceead2fab8d778c3a0fd59def01f49ef9bebe Mon Sep 17 00:00:00 2001 From: Evgenii Date: Fri, 21 Jun 2019 22:40:17 +0300 Subject: [PATCH] Add benchmarks --- tz/hash_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tz/hash_test.go b/tz/hash_test.go index 08ec0c0..222f363 100644 --- a/tz/hash_test.go +++ b/tz/hash_test.go @@ -2,12 +2,15 @@ package tz import ( "encoding/hex" + "io" "math/rand" "testing" "github.com/stretchr/testify/require" ) +const benchDataSize = 1000000 + var testCases = []struct { input []byte hash string @@ -50,6 +53,43 @@ func TestHash(t *testing.T) { }) } +func newBuffer() (data []byte) { + data = make([]byte, benchDataSize) + + r := rand.New(rand.NewSource(0)) + _, err := io.ReadFull(r, data) + if err != nil { + panic("cant initialize buffer") + } + return +} + +func BenchmarkAVX(b *testing.B) { + data := newBuffer() + + b.ResetTimer() + b.ReportAllocs() + d := new(digest) + for i := 0; i < b.N; i++ { + d.Reset() + _, _ = d.Write(data) + d.checkSum() + } +} + +func BenchmarkAVX2(b *testing.B) { + data := newBuffer() + + b.ResetTimer() + b.ReportAllocs() + d := new(digest2) + for i := 0; i < b.N; i++ { + d.Reset() + _, _ = d.Write(data) + d.checkSum() + } +} + func TestHomomorphism(t *testing.T) { var ( c1, c2 sl2