關於Julia 和Matlab速度的比較!(以偏概全)。_julia

來源:互聯網
上載者:User

    在本人機器上,MATLAB是2013A版本, JULIA是0.2版本。
    本人進行了以下幾個比較:
一、矩陣隨機數
JULIA:
julia> @time p=rand(10000,10000)
elapsed time: 0.725364962 seconds (800236500 bytes allocated)
10000x10000 Array{Float64,2}:
MATLAB:
>> tic;p=rand(10000,10000);toc
Elapsed time is 2.718032 seconds.
JULIA勝出。


二、矩陣操作
JULIA:
(1)向量和:小量級
julia> X=1:1000
1:1000
julia> @time sum(X)
elapsed time: 0.00412673 seconds (43028 bytes allocated)
500500
(2)向量和:大數級
julia> a=rand(1,100000000)
1x100000000 Array{Float64,2}:
 0.970678  0.236125  0.446117  0.177539  …  0.469363  0.429614  0.222946
julia> @time sum(a);
elapsed time: 
0.369308621 seconds (64 bytes allocated)
(3) 刪除矩陣某行
julia> a=rand(1000,1000);
julia> @time a=a[[1,3:end],:];
elapsed time: 0.145651394 seconds (10560016 bytes allocated)


MATLAB:
(1)向量和:小量級
>> X=1:1000;
>> tic;sum(X);toc
Elapsed time is 0.000037 seconds.
(2)向量和:大數級
>> a=rand(1,100000000);
>> tic;sum(a);toc;
Elapsed time is 0.085890 seconds.
(3) 刪除矩陣某行
>> a =rand(1000,1000);
>> tic;a(2,:)=[];toc;
Elapsed time is 0.008743 seconds.


MATLAB勝出。可見,MATLAB在向量化計算時,還是有一定優勢的。


三、循還
JULIA:
testfun.jl:
#####################
function testfun()
     p=0.0
     for i=1:10000000
          p=p+0.01;
     end
end
##########################
julia> include("D://strategyJulia//testfun.jl")
testfun (generic function with 1 method)
julia> @time testfun()
elapsed time: 
julia> 
0.014341504 seconds (92820 bytes allocated)
MATLAB:
     %testfun.m
     tic;
     p=0.0;
     for i=1:10000000
          p=p+0.01;
     end
     toc;
     %
>> MATLAB_2012.testfun
Elapsed time is 0.100696 seconds.
   在循還上,JULIA勝出。
   從上面來看,各有優勢。因此,在可以向量操作和循還操作時,JULIA優先推薦使用循還,而不是向量操作。

   綜合以上,個人認為,JULIA的綜合效能更佳。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.