You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

  1. package prover
  2. import (
  3. "crypto/rand"
  4. "math/big"
  5. "testing"
  6. cryptoConstants "github.com/iden3/go-iden3-crypto/constants"
  7. "github.com/iden3/go-iden3-crypto/utils"
  8. )
  9. func randBI() *big.Int {
  10. maxbits := 256
  11. b := make([]byte, (maxbits/8)-1)
  12. _, err := rand.Read(b)
  13. if err != nil {
  14. panic(err)
  15. }
  16. r := new(big.Int).SetBytes(b)
  17. return new(big.Int).Mod(r, cryptoConstants.Q)
  18. }
  19. func BenchmarkArithmetic(b *testing.B) {
  20. // generate arrays with bigint
  21. var p, q []*big.Int
  22. for i := 0; i < 1000; i++ {
  23. pi := randBI()
  24. p = append(p, pi)
  25. }
  26. for i := 1000 - 1; i >= 0; i-- {
  27. q = append(q, p[i])
  28. }
  29. pe := utils.BigIntArrayToElementArray(p)
  30. qe := utils.BigIntArrayToElementArray(q)
  31. b.Run("polynomialSub", func(b *testing.B) {
  32. for i := 0; i < b.N; i++ {
  33. polynomialSub(p, q)
  34. }
  35. })
  36. b.Run("polynomialSubE", func(b *testing.B) {
  37. for i := 0; i < b.N; i++ {
  38. polynomialSubE(pe, qe)
  39. }
  40. })
  41. b.Run("polynomialMul", func(b *testing.B) {
  42. for i := 0; i < b.N; i++ {
  43. polynomialMul(p, q)
  44. }
  45. })
  46. b.Run("polynomialMulE", func(b *testing.B) {
  47. for i := 0; i < b.N; i++ {
  48. polynomialMulE(pe, qe)
  49. }
  50. })
  51. b.Run("polynomialDiv", func(b *testing.B) {
  52. for i := 0; i < b.N; i++ {
  53. polynomialDiv(p, q)
  54. }
  55. })
  56. b.Run("polynomialDivE", func(b *testing.B) {
  57. for i := 0; i < b.N; i++ {
  58. polynomialDivE(pe, qe)
  59. }
  60. })
  61. }