简体   繁体   English

与 Matlab 和 Scilab 相比 Octave 的性能

[英]Performance of Octave compared to Matlab and Scilab

I test the following command in Octave, Scilab and Matlab prompt.我在 Octave、Scilab 和 Matlab 提示符下测试以下命令。

>>  A = rand(10000,10000);
>> B = rand(10000,1);
>> tic,A\B;, toc

The timings were around, respectively, 40, 15.8 and 15.7 sec.时间分别约为 40、15.8 和 15.7 秒。 For comparison Mathematica's performance was为了比较 Mathematica 的性能是

In[7]:= A = RandomReal[{0, 1}, {10000, 10000}];

In[9]:= B = RandomReal[{0, 1}, 10000];

In[10]:= Timing[LinearSolve[A, B];]

Out[10]= {14.125, Null}

Does this indicate that Octave is not so capable as the rest of the softwares in the field of linear equations?这是否表明 Octave 在线性方程领域不如其他软件强大?

I think that your tests are flawed.我认为你的测试有缺陷。 The algorithms behind A\\B make use of the special patterns and structures in the systems of equations, so execution time depends very much on what random(10000,10000) has generated. A\\B背后的算法利用方程组中的特殊模式和结构,因此执行时间在很大程度上取决于random(10000,10000)生成的内容。 On three different runs with Octave 4.0.0 on my machine, your code returns 7.1s , 95.1s and 16.4s .在我的机器上使用 Octave 4.0.0进行三个不同的运行时,您的代码返回7.1s95.1s16.4s That indicates that the first matrix generated by random was probably sparse, and that could have been the case when you tested your code with Scilab and Matlab.这表明随机生成的第一个矩阵可能是稀疏的,当您使用 Scilab 和 Matlab 测试代码时可能就是这种情况。 So unless you make sure that the algorithms are evaluating the same thing, or unless you average the execution time in a sound manner (that is not very trivial to find for me), then it doesn't make sense to compare them as you did.因此,除非您确保算法正在评估相同的事情,或者除非您以合理的方式平均执行时间(这对我来说不是很容易找到),否则像您一样比较它们是没有意义的.

@dimitris thanks for the question, I found your method quite helpful for a quick comparison, and the somewhat different answers I get now are interesting. @dimitris 谢谢你的问题,我发现你的方法对快速比较很有帮助,我现在得到的有些不同的答案很有趣。 I didn't have the problems alluded to by the other respondents, the answers (timings) were consistent and helpful.我没有其他受访者提到的问题,答案(时间)一致且有帮助。

Here are the times on my Windows machine (Asus with Ryzen 7 4700U) where I've printed 5 runs for each of Scilab 6.1.0, Octave 6.2.0, Python 3.8.7 and Julia 1.5.3) - I've been exploring the possible use of them for a job I currently have.这是我的 Windows 机器(配备 Ryzen 7 4700U 的华硕)上的时间,我为 Scilab 6.1.0、Octave 6.2.0、Python 3.8.7 和 Julia 1.5.3 中的每一个打印了 5 次运行) - 我一直在探索如何将它们用于我目前的工作。 I don't have (can't afford..) either Matlab or Mathematica, so no results from these..我没有(买不起..)Matlab 或 Mathematica,所以这些没有结果..

Octave八度

>> for i=1:5;A=rand(10000,10000);B=rand(10000,1);tic;A\B;toc,end;
  Elapsed time is 9.79964 seconds.
  Elapsed time is 9.78249 seconds.
  Elapsed time is 9.70953 seconds.
  Elapsed time is 9.73357 seconds.
  Elapsed time is 9.69932 seconds.

Scilab科学实验室

--> for i=1:5;A=rand(10000,10000);B=rand(10000,1);tic;A\B;toc,end;
 ans  = 10.407628
 ans  = 10.706747
 ans  = 10.490241
 ans  = 10.773073
 ans  = 10.517951

Julia朱莉娅

m=10000;
for i=1:5;
  A=rand(m,m);B=rand(m,1);
  t=time();A\B;
  println(time()-t)
end;
  7.833999872207642
  7.7170000076293945
  7.675999879837036
  7.76200008392334
  7.740999937057495

Python Python

from pylab import *
import numpy as np
import datetime as dt
N = 10000
for i in range(5):
    A = np.random.random((N,N))
    B = np.random.random((N,1))
    tic=dt.datetime.now()
    np.linalg.solve(A,B)
    print((dt.datetime.now()-tic))
  0:00:05.567395
  0:00:05.703859
  0:00:05.050467
  0:00:04.995202
  0:00:05.294050

You should have run the tests in each one probably around a thousand times or more.您应该在每个测试中运行大约一千次或更多次。 Also note they should use the same algorithms but somewhat less fine-tuned.另请注意,它们应该使用相同的算法,但微调稍差。 A more sensible approach is to test across many cases over many different dimensions and average the results.更明智的方法是在许多不同维度的许多案例中进行测试,然后对结果进行平均。

Most matrix math comes from LAPACK.大多数矩阵数学来自LAPACK。 the difference is that Matlab has dlls with fortran and C++ that may be slightly better.不同之处在于,Matlab 有带有 fortran 和 C++ 的 dll,可能会稍微好一些。 I believe that they make a little bit better use of your math coprocessor.我相信他们可以更好地利用您的数学协处理器。 It is called the Intel MKL kernel.它被称为英特尔 MKL 内核。

The actual algorithm changes dependent on the structure of the matrix and size.实际算法的变化取决于矩阵的结构和大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM