关于Julia 和Matlab速度的比较!(以偏概全)。

10 篇文章 0 订阅

    在本人机器上,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的综合性能更佳!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值