@alfrednewman
I tried to replicate your test. On my computer the following (slightly modified
version) of the _nim_ program and the _julia_ program have the same runtime.
Whatever I do, I fail to run the _julia_ version in less than 2 seconds (as you
had). Are you sure that test went OK?
import times, math
proc `/`(a, b: int): float =
float(a) / float(b)
proc leibniz(terms: int): float =
for i in 0..terms:
result += (-1)^i / (2*i+1)
result *= 4.0
let
t0 = cpuTime()
pi = leibniz(100_000_000)
tt = cpuTime() - t0
echo("Elapsed time: ", tt)
echo("Pi: ", pi)
gives
>> nim c -d:release pi.nim
>> time ./pi
Elapsed time: 5.671875
Pi: 3.141592663589326
real 0m5.706s
user 0m5.672s
sys 0m0.000s
and
function leibniz(terms)
res = 0.0
for i in 0:terms
res += (-1.0)^i/(2.0*i+1.0)
end
return res * 4.0
end
println("Pi: ", @time leibniz(100_000_000))
gives
>> time julia pi.jl
5.770856 seconds (4.48 k allocations: 226.962 KB)
Pi: 3.141592663589326
real 0m6.538s
user 0m6.594s
sys 0m0.234s