Add some little tests/benches.
This commit is contained in:
parent
5308d6421c
commit
d1cf077d94
|
@ -0,0 +1,4 @@
|
|||
import sha256_64B {.all.}
|
||||
|
||||
var dig: array[1, Digest]; var b64: array[1, Block64]
|
||||
sha256_64Bs cast[pua Digest](dig[0].addr), cast[pua Block64](b64[0].addr), 1
|
|
@ -0,0 +1,30 @@
|
|||
import std/[random, stats, times, math], sha256_64B{.all.}, cligen/strUt, cligen
|
||||
|
||||
proc benchK(a: Algo, x: seq[uint64], bN=256, mN=5, aN=10, cold=false) =
|
||||
var o = newSeq[Digest](bN) # Output hash/digests
|
||||
var s = 0u64
|
||||
var ra: RunningStat
|
||||
for aj in 0 ..< aN: # Average loop
|
||||
var rm: RunningStat
|
||||
for m in 0 ..< mN: # Minimum loop
|
||||
let t0 = epochTime()
|
||||
sha256_64Bs a, cast[pua Digest](o[0].addr),
|
||||
cast[pua Block64](x[8*(mN*(m + aN*aj))].unsafeAddr), bN
|
||||
rm.push epochTime() - t0 # Note time & below accum chksum
|
||||
for b in 0 ..< bN: s += cast[ptr uint64](o[b][0].addr)[]
|
||||
ra.push (if cold: rm.max else: rm.min) # Avg(Most(Times))
|
||||
let scale = 1e9/bN.float # Want amortized nanosec per hash
|
||||
let sigDt = ra.standardDeviation*scale/ra.n.float.sqrt
|
||||
echo a, " ", fmtUncertain(ra.mean*scale, sigDt), " ", s
|
||||
|
||||
proc bench*(algos: seq[Algo], bN=256, mN=5, aN=10, cold=false) =
|
||||
## Small bench CLI for Potuz' asm hashtree lib largely to get at auto (but
|
||||
## likely static unless we go ATLAS route) method choice on various CPUs.
|
||||
var x: seq[uint64] # Pre-generated rand data
|
||||
for j in 1 .. 8*bN*mN*aN: x.add randState.next
|
||||
for a in algos: benchK(a, x, bN, mN, aN)
|
||||
|
||||
when defined(release): randomize()
|
||||
when defined(linux): import cligen/osUt; setAffinity() # lessen CPU migration
|
||||
dispatch bench, help={"bN":"block count", "mN":"most loop", "aN":"avg loop",
|
||||
"cold": "average max times not min"}
|
|
@ -0,0 +1,9 @@
|
|||
import sha256_64B {.all.}
|
||||
|
||||
proc cpuName(): string = # This is just to test cpuID
|
||||
var leaves {.global.} = cast[array[48, char]]([cpuID(0x80000002'i32),
|
||||
cpuID(0x80000003'i32),
|
||||
cpuID(0x80000004'i32)])
|
||||
$cast[cstring](leaves[0].addr)
|
||||
|
||||
echo cpuName() # Output should match `uname -p` on Unix
|
|
@ -0,0 +1 @@
|
|||
-p:".."
|
Loading…
Reference in New Issue