Skip to content

Commit

Permalink
add case of router for benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Jan 17, 2024
1 parent 6f7f385 commit 67ad04f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions benchmark/trouter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,26 @@ block:
doAssert r.route(HttpGet, r1).status == routingSuccess
doAssert r.route(HttpGet, r2).status == routingSuccess
echo "nest router:", cpuTime() - t2

block caseOf:
proc tCase(meth: HttpMethod, path: string): bool =
case meth
of HttpGet:
if path == "/":
return true
else:
let id1 = path[1 ..< 2]
let id2 = path[4 ..< 5]
return true
of HttpPost:
discard
else:
discard

const r1 = "/"
const r2 = "/p1/p2"
let t2 = cpuTime()
for i in 1..1000:
doAssert tCase(HttpGet, r1) == true
doAssert tCase(HttpGet, r2) == true
echo "case router:", cpuTime() - t2

0 comments on commit 67ad04f

Please sign in to comment.