Created
September 21, 2019 19:29
-
-
Save Muratam/4b3369be66a44fb42bd2538e46da82be to your computer and use it in GitHub Desktop.
bench.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sequtils,times | |
template stopwatch(body) = (let t1 = cpuTime();body;stderr.writeLine "TIME:",(cpuTime() - t1) * 1000,"ms") | |
const N = 10_000_0000 | |
proc newSeqProc*(len: int): seq[int] = | |
result = newSeq[int](len) | |
proc newSeqProc2*(len: int): seq[int] = | |
let x = newSeq[int](len) | |
return x | |
template newSeqTemplate*(len: int): seq[int] = | |
let result = newSeq[int](len) | |
result | |
# at nim 0.20.0 | |
block: | |
stopwatch: # TIME:388.494ms | |
let s = newSeq[int](N) | |
echo s[^1] | |
block: | |
stopwatch: # TIME:387.783ms | |
let s = newSeqProc(N) | |
echo s[^1] | |
block: | |
stopwatch: # TIME:965.893ms | |
let s = newSeqProc2(N) | |
echo s[^1] | |
block: | |
stopwatch: # TIME:1257.918ms | |
let s = newSeqTemplate(N) | |
echo s[^1] |
Author
Muratam
commented
Sep 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment