scalar: add benchmarks for scalar operations
This commit is contained in:
parent
37b8fb5359
commit
51f382caa1
|
@ -5,6 +5,7 @@
|
|||
package edwards25519
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
@ -165,3 +166,43 @@ func BenchmarkMultiScalarMultSize8(t *testing.B) {
|
|||
[]*Point{B, B, B, B, B, B, B, B})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkScalarAddition(b *testing.B) {
|
||||
var rnd [128]byte
|
||||
rand.Read(rnd[:])
|
||||
s1, _ := (&Scalar{}).SetUniformBytes(rnd[0:64])
|
||||
s2, _ := (&Scalar{}).SetUniformBytes(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
|
||||
rand.Read(rnd[:])
|
||||
s1, _ := (&Scalar{}).SetUniformBytes(rnd[0:64])
|
||||
s2, _ := (&Scalar{}).SetUniformBytes(rnd[64:128])
|
||||
t := &Scalar{}
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
t.Multiply(s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkScalarInversion(b *testing.B) {
|
||||
var rnd [64]byte
|
||||
rand.Read(rnd[:])
|
||||
s1, _ := (&Scalar{}).SetUniformBytes(rnd[0:64])
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
s1.Invert(s1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue