mirror of
https://github.com/status-im/nim-stint.git
synced 2025-02-22 03:48:20 +00:00
Add bench of modulo op
This commit is contained in:
parent
c65ab16512
commit
0e7ecaef7a
33
benchmarks/bench_mod.nim
Normal file
33
benchmarks/bench_mod.nim
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import ../src/mpint, times
|
||||||
|
|
||||||
|
|
||||||
|
# Warmup on normal int
|
||||||
|
var start = cpuTime()
|
||||||
|
block:
|
||||||
|
var foo = 123
|
||||||
|
for i in 0 ..< 10_000_000:
|
||||||
|
foo += i*i mod 456
|
||||||
|
foo = foo mod 789
|
||||||
|
|
||||||
|
# Compiler shouldn't optimize away the results as cpuTime rely on sideeffects
|
||||||
|
var stop = cpuTime()
|
||||||
|
echo "Warmup: " & $(stop - start) & "s"
|
||||||
|
|
||||||
|
####################################
|
||||||
|
|
||||||
|
|
||||||
|
start = cpuTime()
|
||||||
|
block:
|
||||||
|
var foo = 123.initMpUint(64)
|
||||||
|
for i in 0 ..< 10_000_000:
|
||||||
|
let i2 = i.initMpUint(64)
|
||||||
|
foo += i2 * i2 mod 456.initMpUint(64)
|
||||||
|
foo = foo mod 789.initMpUint(64)
|
||||||
|
|
||||||
|
stop = cpuTime()
|
||||||
|
echo "Library: " & $(stop - start) & "s"
|
||||||
|
|
||||||
|
# On my i5-5257 broadwell with the flags:
|
||||||
|
# nim c -d:release -d:mpint_test
|
||||||
|
# Warmup: 0.040888s
|
||||||
|
# Library: 5.838267s
|
Loading…
x
Reference in New Issue
Block a user