Add benchmarks

This commit is contained in:
Evgenii 2019-06-21 22:40:17 +03:00
parent 9485f49f3b
commit eaeceead2f

View file

@ -2,12 +2,15 @@ package tz
import ( import (
"encoding/hex" "encoding/hex"
"io"
"math/rand" "math/rand"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const benchDataSize = 1000000
var testCases = []struct { var testCases = []struct {
input []byte input []byte
hash string 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) { func TestHomomorphism(t *testing.T) {
var ( var (
c1, c2 sl2 c1, c2 sl2