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格式保存,这对于有图和公式的文章太方便了。