/ benchmarks / bench_fp.nim
bench_fp.nim
 1  # Constantine
 2  # Copyright (c) 2018-2019    Status Research & Development GmbH
 3  # Copyright (c) 2020-Present Mamy André-Ratsimbazafy
 4  # Licensed and distributed under either of
 5  #   * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
 6  #   * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
 7  # at your option. This file may not be copied, modified, or distributed except according to those terms.
 8  
 9  import
10    # Internals
11    ../constantine/math/config/curves,
12    ../constantine/math/arithmetic,
13    ../constantine/math/io/io_bigints,
14    ../constantine/math/constants/zoo_square_roots,
15    # Helpers
16    ./bench_fields_template
17  
18  # ############################################################
19  #
20  #                  Benchmark of 𝔽p
21  #
22  # ############################################################
23  
24  
25  const Iters = 100_000
26  const ExponentIters = 100
27  const AvailableCurves = [
28    # P224,
29    BN254_Nogami,
30    BN254_Snarks,
31    Edwards25519,
32    Bandersnatch,
33    Pallas,
34    Vesta,
35    P256,
36    Secp256k1,
37    BLS12_377,
38    BLS12_381,
39    BW6_761
40  ]
41  
42  proc main() =
43    separator()
44    staticFor i, 0, AvailableCurves.len:
45      const curve = AvailableCurves[i]
46      addBench(Fp[curve], Iters)
47      subBench(Fp[curve], Iters)
48      negBench(Fp[curve], Iters)
49      ccopyBench(Fp[curve], Iters)
50      div2Bench(Fp[curve], Iters)
51      mulBench(Fp[curve], Iters)
52      sqrBench(Fp[curve], Iters)
53      smallSeparator()
54      mul2xUnrBench(Fp[curve], Iters)
55      sqr2xUnrBench(Fp[curve], Iters)
56      rdc2xBench(Fp[curve], Iters)
57      smallSeparator()
58      sumprodBench(Fp[curve], Iters)
59      smallSeparator()
60      toBigBench(Fp[curve], Iters)
61      toFieldBench(Fp[curve], Iters)
62      smallSeparator()
63      invBench(Fp[curve], ExponentIters)
64      invVartimeBench(Fp[curve], ExponentIters)
65      isSquareBench(Fp[curve], ExponentIters)
66      sqrtBench(Fp[curve], ExponentIters)
67      sqrtRatioBench(Fp[curve], ExponentIters)
68      # Exponentiation by a "secret" of size ~the curve order
69      powBench(Fp[curve], ExponentIters)
70      powUnsafeBench(Fp[curve], ExponentIters)
71      separator()
72  
73  main()
74  notes()