diff --git a/bench/.gitignore b/bench/.gitignore new file mode 100644 index 0000000..b302f53 --- /dev/null +++ b/bench/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +bench_fft diff --git a/bench/bench_fft.nim b/bench/bench_fft.nim new file mode 100644 index 0000000..e3d2d6c --- /dev/null +++ b/bench/bench_fft.nim @@ -0,0 +1,104 @@ + +# +# nimble build -d:release +# + +import strformat + +import taskpools + +import constantine/math/arithmetic +import constantine/named/properties_fields + +import groth16/bn128 +import groth16/bn128/msm +import groth16/bn128/arrays + +import groth16/math/domain +import groth16/math/ntt +import groth16/dynamic/group_fft + +import shared + +#------------------------------------------------------------------------------- + +when isMainModule: + + echo "quick & dirty FFT benchmarks" + + let nthreads: int = 8 + let N: int = 8192 + + let D = createDomain(N) + let xs : seq[Fr[BN254_Snarks]] = randFrSeq(N) + let gs : seq[AffG1] = randG1Seq(N) + + var ys, zs: seq[Fr[BN254_Snarks]] + var hs, rs: seq[AffG1] + + var pool = Taskpool.new(nthreads) + + #----------------------------------------------------------------------------- + + echo "\n----------------------------------------" + echo "*** scalar multiplications\n" + + hs = newSeq[AffG1](N) + withMeasureTime(true , fmt"{N} individual scalar multiplications "): + for i in 0..= 2.2.0" +requires "https://github.com/status-im/nim-taskpools >= 0.0.5" +requires "https://github.com/mratsim/constantine" +requires "groth16 >= 0.1.2" diff --git a/bench/nim.cfg b/bench/nim.cfg new file mode 100644 index 0000000..0f840a1 --- /dev/null +++ b/bench/nim.cfg @@ -0,0 +1 @@ +--path:".." diff --git a/bench/shared.nim b/bench/shared.nim new file mode 100644 index 0000000..ef568d1 --- /dev/null +++ b/bench/shared.nim @@ -0,0 +1,23 @@ + +import strformat +import times, strutils + +#------------------------------------------------------------------------------- + +func seconds*(x: float): string = fmt"{x:.4f} seconds" + +func quoted*(s: string): string = fmt"`{s:s}`" + +template withMeasureTime*(doPrint: bool, text: string, code: untyped) = + block: + if doPrint: + let t0 = epochTime() + code + let elapsed = epochTime() - t0 + let elapsedStr = elapsed.formatFloat(format = ffDecimal, precision = 4) + echo ( text & " took " & elapsedStr & " seconds" ) + else: + code + +#------------------------------------------------------------------------------- + diff --git a/groth16.nimble b/groth16.nimble index ec8762a..be06ac4 100644 --- a/groth16.nimble +++ b/groth16.nimble @@ -4,7 +4,7 @@ author = "Balazs Komuves" description = "Groth16 proof system" license = "MIT OR Apache-2.0" -skipDirs = @["groth16/example"] +skipDirs = @["groth16/example","bench"] binDir = "build" namedBin = {"cli/cli_main": "nim-groth16"}.toTable() installExt = @["nim"] diff --git a/groth16/bn128/arrays.nim b/groth16/bn128/arrays.nim new file mode 100644 index 0000000..0b65368 --- /dev/null +++ b/groth16/bn128/arrays.nim @@ -0,0 +1,61 @@ + +import constantine/math/arithmetic +import constantine/named/properties_fields + +import groth16/bn128/fields +import groth16/bn128/curves +import groth16/bn128/rnd + +#------------------------------------------------------------------------------- +# Fr arrays + +proc randFrSeq*(N: int) : seq[Fr[BN254_Snarks]] = + var xs : seq[Fr[BN254_Snarks]] = newSeq[Fr[BN254_Snarks]]( N ) + for i in 0..