mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-23 16:08:40 +00:00
cleanup
This commit is contained in:
parent
e07c767772
commit
6da023af0c
@ -1,5 +1,7 @@
|
|||||||
import std/[hashes, json, strutils, strformat, os, osproc]
|
import std/[hashes, json, strutils, strformat, os, osproc]
|
||||||
|
|
||||||
|
import ./utils
|
||||||
|
|
||||||
type
|
type
|
||||||
CircuitEnv* = object
|
CircuitEnv* = object
|
||||||
nimCircuitCli*: string
|
nimCircuitCli*: string
|
||||||
@ -32,21 +34,6 @@ func default*(tp: typedesc[CircuitEnv]): CircuitEnv =
|
|||||||
result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau/"
|
result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau/"
|
||||||
result.codexProjDir = codexDir
|
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) =
|
proc check*(env: var CircuitEnv) =
|
||||||
## check that the CWD of script is in the codex parent
|
## check that the CWD of script is in the codex parent
|
||||||
let codexProjDir = findCodexProjectDir()
|
let codexProjDir = findCodexProjectDir()
|
||||||
|
@ -9,6 +9,7 @@ import pkg/codex/utils/[json, poseidon2digest]
|
|||||||
import pkg/codex/slots/[builder, sampler/utils, backends/helpers]
|
import pkg/codex/slots/[builder, sampler/utils, backends/helpers]
|
||||||
import pkg/constantine/math/[arithmetic, io/io_bigints, io/io_fields]
|
import pkg/constantine/math/[arithmetic, io/io_bigints, io/io_fields]
|
||||||
|
|
||||||
|
import ./utils
|
||||||
import ./create_circuits
|
import ./create_circuits
|
||||||
|
|
||||||
type CircuitFiles* = object
|
type CircuitFiles* = object
|
||||||
@ -17,23 +18,6 @@ type CircuitFiles* = object
|
|||||||
zkey*: string
|
zkey*: string
|
||||||
inputs*: 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) =
|
proc runArkCircom(args: CircuitArgs, files: CircuitFiles) =
|
||||||
echo "Loading sample proof..."
|
echo "Loading sample proof..."
|
||||||
var
|
var
|
||||||
|
34
benchmarks/utils.nim
Normal file
34
benchmarks/utils.nim
Normal 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"
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user