mirror of
https://github.com/status-im/nim-stint.git
synced 2025-02-21 11:28:23 +00:00
49 lines
1.0 KiB
Nim
49 lines
1.0 KiB
Nim
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(128)
|
|
for i in 0 ..< 10_000_000:
|
|
foo += i.initMpUint(128) * i.initMpUint(128) mod 456.initMpUint(128)
|
|
foo = foo mod 789.initMpUint(128)
|
|
|
|
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
|
|
|
|
when defined(bench_ttmath):
|
|
# need C++
|
|
import ttmath
|
|
|
|
template tt_u256(a: int): UInt[256] = ttmath.u256(a.uint)
|
|
|
|
start = cpuTime()
|
|
block:
|
|
var foo = 123.tt_u256
|
|
for i in 0 ..< 10_000_000:
|
|
foo += i.tt_u256 * i.tt_u256 mod 456.tt_u256
|
|
foo = foo mod 789.tt_u256
|
|
|
|
stop = cpuTime()
|
|
echo "TTMath: " & $(stop - start) & "s"
|