mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-07 03:16:46 +01:00
Add polynomials arithmetic in goff
Polynomials and ifft moved to goff (iden3/go-iden3-crypto/ff) instead of *big.Int. Benchmarks: - Before: BenchmarkArithmetic/polynomialSub-4 2774 441063 ns/op BenchmarkArithmetic/polynomialMul-4 1 1135732757 ns/op BenchmarkArithmetic/polynomialDiv-4 768 1425192 ns/op BenchmarkGenerateProof-4 1 2844488975 ns/op - With this commit: BenchmarkArithmetic/polynomialSubE-4 23097 54152 ns/op BenchmarkArithmetic/polynomialMulE-4 25 44914327 ns/op BenchmarkArithmetic/polynomialDivE-4 8703 132573 ns/op BenchmarkGenerateProof-4 1 1530398526 ns/op
This commit is contained in:
66
prover/arithmetic_test.go
Normal file
66
prover/arithmetic_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package prover
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
cryptoConstants "github.com/iden3/go-iden3-crypto/constants"
|
||||
"github.com/iden3/go-iden3-crypto/utils"
|
||||
)
|
||||
|
||||
func randBI() *big.Int {
|
||||
maxbits := 253
|
||||
b := make([]byte, (maxbits/8)-1)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
r := new(big.Int).SetBytes(b)
|
||||
return new(big.Int).Mod(r, cryptoConstants.Q)
|
||||
}
|
||||
|
||||
func BenchmarkArithmetic(b *testing.B) {
|
||||
// generate arrays with bigint
|
||||
var p, q []*big.Int
|
||||
for i := 0; i < 1000; i++ {
|
||||
pi := randBI()
|
||||
p = append(p, pi)
|
||||
}
|
||||
for i := 1000 - 1; i >= 0; i-- {
|
||||
q = append(q, p[i])
|
||||
}
|
||||
pe := utils.BigIntArrayToElementArray(p)
|
||||
qe := utils.BigIntArrayToElementArray(q)
|
||||
|
||||
b.Run("polynomialSub", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialSub(p, q)
|
||||
}
|
||||
})
|
||||
b.Run("polynomialSubE", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialSubE(pe, qe)
|
||||
}
|
||||
})
|
||||
b.Run("polynomialMul", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialMul(p, q)
|
||||
}
|
||||
})
|
||||
b.Run("polynomialMulE", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialMulE(pe, qe)
|
||||
}
|
||||
})
|
||||
b.Run("polynomialDiv", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialDiv(p, q)
|
||||
}
|
||||
})
|
||||
b.Run("polynomialDivE", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
polynomialDivE(pe, qe)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user