一篇不錯的介紹Julia和matlab關係的文章

lt發表於2017-04-20

http://freemind.pluskid.org/technology/julia-a-new-language-for-scientific-computing/
另外,我找到了人工迴圈慢的原因,出在變數型別上,把整型常量改為浮點型,記憶體就和dot_dot一樣的

function dot_loop(x,y)
   z = 0
   for i = 1:length(x)
       z += x[i]*y[i]
   end
    return z
end

function dot_loopf(x,y)
   z = 0.0  #只改了這裡
   for i = 1:length(x)
       z += x[i]*y[i]
   end
    return z
end

執行結果

julia> include("dot_jl.txt")
@timeit (macro with 1 method)

julia> @timeit dot_loop
  dot_loop   0.379606 seconds (6.00 M allocations: 68.665 MB, 51.75% gc time)

julia> @timeit dot_vec
   dot_vec   0.015613 seconds (800 allocations: 15.279 MB)

julia> @timeit dot_dot
   dot_dot   0.001550 seconds (200 allocations: 2.344 KB)

julia> @timeit dot_loop
  dot_loop   0.289739 seconds (6.00 M allocations: 68.665 MB, 36.22% gc time)

julia> @timeit dot_loopf
 dot_loopf   0.003579 seconds (200 allocations: 2.344 KB)

另外,他的文章可以用pdf格式儲存,這對於有圖和公式的文章太方便了。

相關文章