forked from TrueCloudLab/tzhash
Add benchmarks
This commit is contained in:
parent
9485f49f3b
commit
eaeceead2f
1 changed files with 40 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue