I tried this for benchmarking
import future, sequtils, times, math
const
LoopCnt = 100_000_000
var
sq: seq[float] = newSeqWith(LoopCnt, 0.0)
t0 = epochTime()
proc setupSeq() =
for i in 0..<LoopCnt: sq[i] = i.float
proc useIt() =
t0 = epochTime()
sq.applyIt(pow(it,2))
echo "applyIt: ", epochTime() - t0
proc useClosure() =
t0 = epochTime()
sq.apply(x => pow(x,2))
echo "closure: ", epochTime() - t0
proc useLoop1() =
t0 = epochTime()
for i in 0..<LoopCnt: sq[i] = pow(sq[i], 2)
echo "loop1: ", epochTime() - t0
proc useLoop2() =
t0 = epochTime()
for i in 0..<LoopCnt: sq[i] = sq[i] * sq[i]
echo "loop2: ", epochTime() - t0
proc main() =
setupSeq()
useIt()
setupSeq()
useIt()
setupSeq()
useClosure()
setupSeq()
useClosure()
setupSeq()
useLoop1()
setupSeq()
useLoop1()
setupSeq()
useLoop2()
setupSeq()
useLoop2()
setupSeq()
main()
- Do we really like the ...It templates? Stefan_Salewski
- Re: Do we really like the ...It templates? Araq
- Re: Do we really like the ...It templates? mratsim
- Re: Do we really like the ...It templates? Varriount
- Re: Do we really like the ...It templates... Skrylar
- Re: Do we really like the ...It temp... olwi
- Re: Do we really like the ...It ... mratsim
- Re: Do we really like the ..... Arrrrrrrrr
- Re: Do we really like the ..... cdome
- Re: Do we really like the ..... jlp765
- Re: Do we really like the ..... doofenstein
- Re: Do we really like the ..... Udiknedormin
- Re: Do we really like the ..... niofis
