Skip to content

Commit

Permalink
Fix benchmark on ARM (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim authored Jun 4, 2020
1 parent 82ceca6 commit 3d1b1fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions benchmarks/bench_elliptic_template.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ proc separator*() =
proc report(op, elliptic: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
let ns = inNanoseconds((stop-start) div iters)
let throughput = 1e9 / float64(ns)
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
when SupportsGetTicks:
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
else:
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op"

macro fixEllipticDisplay(T: typedesc): untyped =
# At compile-time, enums are integers and their display is buggy
Expand All @@ -90,12 +93,18 @@ macro fixEllipticDisplay(T: typedesc): untyped =

template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
let start = getMonotime()
let startClk = getTicks()
when SupportsGetTicks:
let startClk = getTicks()
for _ in 0 ..< iters:
body
let stopClk = getTicks()
when SupportsGetTicks:
let stopClk = getTicks()
let stop = getMonotime()

when not SupportsGetTicks:
let startClk = -1'i64
let stopClk = -1'i64

report(op, fixEllipticDisplay(T), start, stop, startClk, stopClk, iters)

proc addBench*(T: typedesc, iters: int) =
Expand Down
15 changes: 12 additions & 3 deletions benchmarks/bench_fields_template.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ proc separator*() =
proc report(op, field: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
let ns = inNanoseconds((stop-start) div iters)
let throughput = 1e9 / float64(ns)
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
when SupportsGetTicks:
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
else:
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op"

macro fixFieldDisplay(T: typedesc): untyped =
# At compile-time, enums are integers and their display is buggy
Expand All @@ -88,12 +91,18 @@ macro fixFieldDisplay(T: typedesc): untyped =

template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
let start = getMonotime()
let startClk = getTicks()
when SupportsGetTicks:
let startClk = getTicks()
for _ in 0 ..< iters:
body
let stopClk = getTicks()
when SupportsGetTicks:
let stopClk = getTicks()
let stop = getMonotime()

when not SupportsGetTicks:
let startClk = -1'i64
let stopClk = -1'i64

report(op, fixFieldDisplay(T), start, stop, startClk, stopClk, iters)

proc addBench*(T: typedesc, iters: int) =
Expand Down

0 comments on commit 3d1b1fa

Please sign in to comment.