diff --git a/.gitignore b/.gitignore index 41f61d0..2871150 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ !*/ !*.* .nimble -poseidon2.out \ No newline at end of file +poseidon2.out +.DS_store \ No newline at end of file diff --git a/bench/bench_perm.nim b/bench/bench_perm.nim new file mode 100644 index 0000000..870f326 --- /dev/null +++ b/bench/bench_perm.nim @@ -0,0 +1,63 @@ + +# +# nimble build -d:release +# + +import strformat +import times, os, strutils + +import constantine/math/arithmetic +import constantine/math/io/io_fields +import constantine/math/io/io_bigints + +import poseidon2/types +import poseidon2/io +import poseidon2/permutation + +#------------------------------------------------------------------------------- + +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 + +#------------------------------------------------------------------------------- + +proc iteratePerm(n: int) = + + var x: F = toF(0) + var y: F = toF(1) + var z: F = toF(2) + + for i in 0..