internal/scalar: add benchmarks

This commit is contained in:
George Tankersley 2021-02-19 18:54:44 -08:00
parent a83cb39e47
commit 67661f6a4f
1 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@ package scalar
import (
"bytes"
crand "crypto/rand"
"math/big"
"testing"
"testing/quick"
@ -135,3 +136,31 @@ func TestInvert(t *testing.T) {
t.Error(err)
}
}
func BenchmarkScalarAddition(b *testing.B) {
var rnd [128]byte
crand.Read(rnd[:])
s1 := (&Scalar{}).FromUniformBytes(rnd[0:64])
s2 := (&Scalar{}).FromUniformBytes(rnd[64:128])
t := &Scalar{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t.Add(s1, s2)
}
}
func BenchmarkScalarMultiplication(b *testing.B) {
var rnd [128]byte
crand.Read(rnd[:])
s1 := (&Scalar{}).FromUniformBytes(rnd[0:64])
s2 := (&Scalar{}).FromUniformBytes(rnd[64:128])
t := &Scalar{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t.Mul(s1, s2)
}
}