This commit is contained in:
Jaremy Creechley 2024-05-02 15:56:05 +03:00
parent e07c767772
commit 6da023af0c
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 37 additions and 32 deletions

View File

@ -1,5 +1,7 @@
import std/[hashes, json, strutils, strformat, os, osproc]
import ./utils
type
CircuitEnv* = object
nimCircuitCli*: string
@ -32,21 +34,6 @@ func default*(tp: typedesc[CircuitEnv]): CircuitEnv =
result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau/"
result.codexProjDir = codexDir
template withDir(dir: string, blk: untyped) =
## set working dir for duration of blk
let prev = getCurrentDir()
try:
setCurrentDir(dir)
`blk`
finally:
setCurrentDir(prev)
template runit(cmd: string) =
echo "RUNNING: ", cmd
let cmdRes = execShellCmd(cmd)
echo "STATUS: ", cmdRes
assert cmdRes == 0
proc check*(env: var CircuitEnv) =
## check that the CWD of script is in the codex parent
let codexProjDir = findCodexProjectDir()

View File

@ -9,6 +9,7 @@ import pkg/codex/utils/[json, poseidon2digest]
import pkg/codex/slots/[builder, sampler/utils, backends/helpers]
import pkg/constantine/math/[arithmetic, io/io_bigints, io/io_fields]
import ./utils
import ./create_circuits
type CircuitFiles* = object
@ -17,23 +18,6 @@ type CircuitFiles* = object
zkey*: string
inputs*: string
template benchmark(benchmarkName: string, blk: untyped) =
let nn = 5
var vals = newSeqOfCap[float](nn)
for i in 1 .. nn:
block:
let t0 = epochTime()
`blk`
let elapsed = epochTime() - t0
vals.add elapsed
var elapsedStr = ""
for v in vals:
elapsedStr &= ", " & v.formatFloat(format = ffDecimal, precision = 3)
stdout.styledWriteLine(
fgGreen, "CPU Time [", benchmarkName, "] ", "avg(", $nn, "): ", elapsedStr, " s"
)
proc runArkCircom(args: CircuitArgs, files: CircuitFiles) =
echo "Loading sample proof..."
var

34
benchmarks/utils.nim Normal file
View File

@ -0,0 +1,34 @@
template withDir*(dir: string, blk: untyped) =
## set working dir for duration of blk
let prev = getCurrentDir()
try:
setCurrentDir(dir)
`blk`
finally:
setCurrentDir(prev)
template runit*(cmd: string) =
## run shell commands and verify it runs without an error code
echo "RUNNING: ", cmd
let cmdRes = execShellCmd(cmd)
echo "STATUS: ", cmdRes
assert cmdRes == 0
template benchmark*(benchmarkName: string, blk: untyped) =
## simple benchmarking of a block of code
let nn = 5
var vals = newSeqOfCap[float](nn)
for i in 1 .. nn:
block:
let t0 = epochTime()
`blk`
let elapsed = epochTime() - t0
vals.add elapsed
var elapsedStr = ""
for v in vals:
elapsedStr &= ", " & v.formatFloat(format = ffDecimal, precision = 3)
stdout.styledWriteLine(
fgGreen, "CPU Time [", benchmarkName, "] ", "avg(", $nn, "): ", elapsedStr, " s"
)