Benchmark RLN proof generation/verification (#2410)

This commit is contained in:
Alvaro Revuelta 2024-02-09 17:06:25 +01:00 committed by GitHub
parent 2d46c35117
commit e6002032eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 0 deletions

View File

@ -174,6 +174,10 @@ wakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims
benchmarks: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim benchmarks $(NIM_PARAMS) waku.nims
testwakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim testwakunode2 $(NIM_PARAMS) waku.nims

View File

@ -0,0 +1,47 @@
import
math,
std/sequtils,
stew/results,
options,
../../waku/waku_rln_relay/protocol_types,
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay,
../../waku/waku_rln_relay/conversion_utils,
../../waku/waku_rln_relay/group_manager/static/group_manager
import std/[times, os]
proc main(): Future[string] {.async, gcsafe.} =
let rlnIns = createRLNInstance(20).get()
let credentials = toSeq(0 .. 1000).mapIt(membershipKeyGen(rlnIns).get())
let manager = StaticGroupManager(
rlnInstance: rlnIns,
groupSize: 1000,
membershipIndex: some(MembershipIndex(900)),
groupKeys: credentials,
)
await manager.init()
let data: seq[byte] = newSeq[byte](1024)
var proofGenTimes: seq[times.Duration] = @[]
var proofVerTimes: seq[times.Duration] = @[]
for i in 0 .. 50:
var time = getTime()
let proof = manager.generateProof(data, getCurrentEpoch()).get()
proofGenTimes.add(getTime() - time)
time = getTime()
let res = manager.verifyProof(data, proof).get()
proofVerTimes.add(getTime() - time)
echo "Proof generation times: ", sum(proofGenTimes) div len(proofGenTimes)
echo "Proof verification times: ", sum(proofVerTimes) div len(proofVerTimes)
when isMainModule:
try:
waitFor(main())
except CatchableError as e:
raise e

View File

@ -62,6 +62,10 @@ task wakunode2, "Build Waku v2 cli node":
let name = "wakunode2"
buildBinary name, "apps/wakunode2/"
task benchmarks, "Some benchmarks":
let name = "benchmarks"
buildBinary name, "apps/benchmarks/"
task wakucanary, "Build waku-canary tool":
let name = "wakucanary"
buildBinary name, "apps/wakucanary/"