Skip to content

Commit 3d1b1fa

Browse files
authoredJun 4, 2020
Fix benchmark on ARM (#31)
1 parent 82ceca6 commit 3d1b1fa

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed
 

‎benchmarks/bench_elliptic_template.nim

+12-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ proc separator*() =
7676
proc report(op, elliptic: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
7777
let ns = inNanoseconds((stop-start) div iters)
7878
let throughput = 1e9 / float64(ns)
79-
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
79+
when SupportsGetTicks:
80+
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
81+
else:
82+
echo &"{op:<40} {elliptic:<40} {throughput:>15.3f} ops/s {ns:>9} ns/op"
8083

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

9194
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
9295
let start = getMonotime()
93-
let startClk = getTicks()
96+
when SupportsGetTicks:
97+
let startClk = getTicks()
9498
for _ in 0 ..< iters:
9599
body
96-
let stopClk = getTicks()
100+
when SupportsGetTicks:
101+
let stopClk = getTicks()
97102
let stop = getMonotime()
98103

104+
when not SupportsGetTicks:
105+
let startClk = -1'i64
106+
let stopClk = -1'i64
107+
99108
report(op, fixEllipticDisplay(T), start, stop, startClk, stopClk, iters)
100109

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

‎benchmarks/bench_fields_template.nim

+12-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ proc separator*() =
7676
proc report(op, field: string, start, stop: MonoTime, startClk, stopClk: int64, iters: int) =
7777
let ns = inNanoseconds((stop-start) div iters)
7878
let throughput = 1e9 / float64(ns)
79-
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
79+
when SupportsGetTicks:
80+
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
81+
else:
82+
echo &"{op:<15} {field:<18} {throughput:>15.3f} ops/s {ns:>9} ns/op"
8083

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

8992
template bench(op: string, T: typedesc, iters: int, body: untyped): untyped =
9093
let start = getMonotime()
91-
let startClk = getTicks()
94+
when SupportsGetTicks:
95+
let startClk = getTicks()
9296
for _ in 0 ..< iters:
9397
body
94-
let stopClk = getTicks()
98+
when SupportsGetTicks:
99+
let stopClk = getTicks()
95100
let stop = getMonotime()
96101

102+
when not SupportsGetTicks:
103+
let startClk = -1'i64
104+
let stopClk = -1'i64
105+
97106
report(op, fixFieldDisplay(T), start, stop, startClk, stopClk, iters)
98107

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

0 commit comments

Comments
 (0)
Please sign in to comment.