From 3d1b1fab9825ec8b5ba5da6cc236b420b408a4be Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Thu, 4 Jun 2020 22:09:30 +0200 Subject: [PATCH] Fix benchmark on ARM (#31) --- benchmarks/bench_elliptic_template.nim | 15 ++++++++++++--- benchmarks/bench_fields_template.nim | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/benchmarks/bench_elliptic_template.nim b/benchmarks/bench_elliptic_template.nim index 07d94e7fc..d1ccf7351 100644 --- a/benchmarks/bench_elliptic_template.nim +++ b/benchmarks/bench_elliptic_template.nim @@ -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 @@ -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) = diff --git a/benchmarks/bench_fields_template.nim b/benchmarks/bench_fields_template.nim index e6ced402d..6227887ee 100644 --- a/benchmarks/bench_fields_template.nim +++ b/benchmarks/bench_fields_template.nim @@ -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 @@ -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) =