2020-06-15 22:58:56 +02:00
|
|
|
# Constantine
|
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
|
|
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
|
|
|
# Internals
|
2022-02-27 01:49:08 +01:00
|
|
|
../constantine/math/config/curves,
|
|
|
|
../constantine/math/arithmetic,
|
|
|
|
../constantine/math/extension_fields,
|
|
|
|
../constantine/math/elliptic/[
|
2020-10-02 00:01:09 +02:00
|
|
|
ec_shortweierstrass_projective,
|
2023-02-16 12:45:05 +01:00
|
|
|
ec_shortweierstrass_jacobian,
|
|
|
|
ec_shortweierstrass_jacobian_extended],
|
2020-06-15 22:58:56 +02:00
|
|
|
# Helpers
|
|
|
|
./bench_elliptic_template,
|
|
|
|
# Standard library
|
|
|
|
std/strutils
|
|
|
|
|
|
|
|
# ############################################################
|
|
|
|
#
|
|
|
|
# Benchmark of the G1 group of
|
|
|
|
# Short Weierstrass elliptic curves
|
|
|
|
# in (homogeneous) projective coordinates
|
|
|
|
#
|
|
|
|
# ############################################################
|
|
|
|
|
|
|
|
|
2020-09-21 23:24:00 +02:00
|
|
|
const Iters = 10_000
|
2020-06-15 22:58:56 +02:00
|
|
|
const MulIters = 500
|
|
|
|
const AvailableCurves = [
|
|
|
|
# P224,
|
2020-10-10 18:53:48 +02:00
|
|
|
BN254_Nogami,
|
2020-06-15 22:58:56 +02:00
|
|
|
BN254_Snarks,
|
2022-02-27 01:49:08 +01:00
|
|
|
# Edwards25519,
|
2020-06-15 22:58:56 +02:00
|
|
|
# P256,
|
|
|
|
# Secp256k1,
|
2020-09-27 09:15:14 +02:00
|
|
|
BLS12_377,
|
2020-06-15 22:58:56 +02:00
|
|
|
BLS12_381,
|
|
|
|
]
|
|
|
|
|
|
|
|
proc main() =
|
|
|
|
separator()
|
|
|
|
staticFor i, 0, AvailableCurves.len:
|
|
|
|
const curve = AvailableCurves[i]
|
2022-01-01 19:17:04 +01:00
|
|
|
addBench(ECP_ShortW_Prj[Fp2[curve], G2], Iters)
|
|
|
|
addBench(ECP_ShortW_Jac[Fp2[curve], G2], Iters)
|
2023-02-16 12:45:05 +01:00
|
|
|
addBench(ECP_ShortW_JacExt[Fp2[curve], G2], Iters)
|
2022-01-01 19:17:04 +01:00
|
|
|
mixedAddBench(ECP_ShortW_Prj[Fp2[curve], G2], Iters)
|
|
|
|
mixedAddBench(ECP_ShortW_Jac[Fp2[curve], G2], Iters)
|
2023-02-16 12:45:05 +01:00
|
|
|
mixedAddBench(ECP_ShortW_JacExt[Fp2[curve], G2], Iters)
|
2022-01-01 19:17:04 +01:00
|
|
|
doublingBench(ECP_ShortW_Prj[Fp2[curve], G2], Iters)
|
|
|
|
doublingBench(ECP_ShortW_Jac[Fp2[curve], G2], Iters)
|
2023-02-16 12:45:05 +01:00
|
|
|
doublingBench(ECP_ShortW_JacExt[Fp2[curve], G2], Iters)
|
2020-10-02 00:01:09 +02:00
|
|
|
separator()
|
2022-01-01 19:17:04 +01:00
|
|
|
affFromProjBench(ECP_ShortW_Prj[Fp2[curve], G2], MulIters)
|
|
|
|
affFromJacBench(ECP_ShortW_Jac[Fp2[curve], G2], MulIters)
|
2020-06-15 22:58:56 +02:00
|
|
|
separator()
|
2023-02-16 12:45:05 +01:00
|
|
|
for numPoints in [10, 100, 1000, 10000]:
|
|
|
|
let batchIters = max(1, Iters div numPoints)
|
|
|
|
affFromProjBatchBench(ECP_ShortW_Prj[Fp[curve], G1], numPoints, useBatching = false, batchIters)
|
2020-06-15 22:58:56 +02:00
|
|
|
separator()
|
2023-02-16 12:45:05 +01:00
|
|
|
for numPoints in [10, 100, 1000, 10000]:
|
|
|
|
let batchIters = max(1, Iters div numPoints)
|
|
|
|
affFromProjBatchBench(ECP_ShortW_Prj[Fp[curve], G1], numPoints, useBatching = true, batchIters)
|
2023-02-07 16:27:53 +01:00
|
|
|
separator()
|
2023-02-16 12:45:05 +01:00
|
|
|
for numPoints in [10, 100, 1000, 10000]:
|
|
|
|
let batchIters = max(1, Iters div numPoints)
|
|
|
|
affFromJacBatchBench(ECP_ShortW_Jac[Fp[curve], G1], numPoints, useBatching = false, batchIters)
|
2020-09-03 23:10:48 +02:00
|
|
|
separator()
|
2023-02-16 12:45:05 +01:00
|
|
|
for numPoints in [10, 100, 1000, 10000]:
|
|
|
|
let batchIters = max(1, Iters div numPoints)
|
|
|
|
affFromJacBatchBench(ECP_ShortW_Jac[Fp[curve], G1], numPoints, useBatching = true, batchIters)
|
2020-06-15 22:58:56 +02:00
|
|
|
separator()
|
2020-09-27 09:15:14 +02:00
|
|
|
separator()
|
2020-06-15 22:58:56 +02:00
|
|
|
|
|
|
|
main()
|
2020-07-24 22:02:30 +02:00
|
|
|
notes()
|