mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-07 15:43:08 +00:00
Fix benchmark on ARM (#31)
This commit is contained in:
parent
82ceca6e3b
commit
3d1b1fab98
@ -76,7 +76,10 @@ proc separator*() =
|
|||||||
proc report(op, elliptic: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
|
proc report(op, elliptic: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
|
||||||
let ns = inNanoseconds((stop-start) div iters)
|
let ns = inNanoseconds((stop-start) div iters)
|
||||||
let throughput = 1e9 / float64(ns)
|
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 =
|
macro fixEllipticDisplay(T: typedesc): untyped =
|
||||||
# At compile-time, enums are integers and their display is buggy
|
# At compile-time, enums are integers and their display is buggy
|
||||||
@ -90,12 +93,18 @@ macro fixEllipticDisplay(T: typedesc): untyped =
|
|||||||
|
|
||||||
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
|
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
|
||||||
let start = getMonotime()
|
let start = getMonotime()
|
||||||
let startClk = getTicks()
|
when SupportsGetTicks:
|
||||||
|
let startClk = getTicks()
|
||||||
for _ in 0 ..< iters:
|
for _ in 0 ..< iters:
|
||||||
body
|
body
|
||||||
let stopClk = getTicks()
|
when SupportsGetTicks:
|
||||||
|
let stopClk = getTicks()
|
||||||
let stop = getMonotime()
|
let stop = getMonotime()
|
||||||
|
|
||||||
|
when not SupportsGetTicks:
|
||||||
|
let startClk = -1'i64
|
||||||
|
let stopClk = -1'i64
|
||||||
|
|
||||||
report(op, fixEllipticDisplay(T), start, stop, startClk, stopClk, iters)
|
report(op, fixEllipticDisplay(T), start, stop, startClk, stopClk, iters)
|
||||||
|
|
||||||
proc addBench*(T: typedesc, iters: int) =
|
proc addBench*(T: typedesc, iters: int) =
|
||||||
|
|||||||
@ -76,7 +76,10 @@ proc separator*() =
|
|||||||
proc report(op, field: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
|
proc report(op, field: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
|
||||||
let ns = inNanoseconds((stop-start) div iters)
|
let ns = inNanoseconds((stop-start) div iters)
|
||||||
let throughput = 1e9 / float64(ns)
|
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 =
|
macro fixFieldDisplay(T: typedesc): untyped =
|
||||||
# At compile-time, enums are integers and their display is buggy
|
# At compile-time, enums are integers and their display is buggy
|
||||||
@ -88,12 +91,18 @@ macro fixFieldDisplay(T: typedesc): untyped =
|
|||||||
|
|
||||||
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
|
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
|
||||||
let start = getMonotime()
|
let start = getMonotime()
|
||||||
let startClk = getTicks()
|
when SupportsGetTicks:
|
||||||
|
let startClk = getTicks()
|
||||||
for _ in 0 ..< iters:
|
for _ in 0 ..< iters:
|
||||||
body
|
body
|
||||||
let stopClk = getTicks()
|
when SupportsGetTicks:
|
||||||
|
let stopClk = getTicks()
|
||||||
let stop = getMonotime()
|
let stop = getMonotime()
|
||||||
|
|
||||||
|
when not SupportsGetTicks:
|
||||||
|
let startClk = -1'i64
|
||||||
|
let stopClk = -1'i64
|
||||||
|
|
||||||
report(op, fixFieldDisplay(T), start, stop, startClk, stopClk, iters)
|
report(op, fixFieldDisplay(T), start, stop, startClk, stopClk, iters)
|
||||||
|
|
||||||
proc addBench*(T: typedesc, iters: int) =
|
proc addBench*(T: typedesc, iters: int) =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user