简体   繁体   English

为什么Octave比MATLAB慢?

[英]Why is Octave slower than MATLAB?

I have been using Octave and MATLAB for a few projects, and I've come across a few questions. 我一直在使用Octave和MATLAB进行一些项目,我遇到了一些问题。 This question Why/when should I prefer MATLAB over Octave? 这个问题为什么/什么时候我更喜欢MATLAB而不是Octave? ) answered several, but there is still one lingering... 回答了几个,但还是有一个挥之不去......

I've read a number of posts/other sources comparing performance of Octave and MATLAB, and I've run some of my own tests on standard scripts that confirm the general consensus that Octave is generally much slower than MATLAB for standard operations (iterated, of course, so that the comparison is meaningful). 我已经阅读了一些帖子/其他来源,比较了Octave和MATLAB的性能,并且我在标准脚本上运行了一些自己的测试,证实了Octave通常比标准操作的MATLAB慢得多(迭代,当然,这样比较是有意义的)。

The consensus also seems to suggest that most of MATLAB's performance boost is attributable to its JIT compiler, which compiles large loops at runtime. 这一共识似乎也表明,大多数MATLAB的性能提升都归功于它的JIT编译器,它在运行时编译大型循环。 This makes sense, and the largest performance differences appear to occur in these cases (eg Mathworks Matlab vs Gnu Octave ) 这是有道理的,在这些情况下似乎会出现最大的性能差异(例如Mathworks Matlab与Gnu Octave

My question is the following: why should it be the case that vectorized code also runs more slowly in Octave? 我的问题如下:为什么矢量化代码在Octave中运行得更慢? It seems that in this case memory should be set aside before the loop and some native C/C++ loop should perform the operation, which would equate performance between Octave and MATLAB for vectorized code. 在这种情况下,似乎应该在循环之前留出内存,并且一些本机C / C ++循环应该执行操作,这将等同于Octave和MATLAB之间的矢量化代码的性能。 Additionally, does this have broader implications, ie that Octave might perform more poorly for complex operations, even if code is written such that a JIT compiler is unneeded/unused? 另外,这是否具有更广泛的含义,即即使编写代码使得JIT编译器不需要/未使用,Octave可能对复杂操作执行得更差?

There are four ways how Matlab code gets sped up: Matlab代码加速的方式有四种:

  • JIT: compiling at runtime helps with loops but seems to speed up (or at least interact with) other parts of the code as well, according to my anecdotal observations. JIT:根据我的轶事观察,在运行时编译有助于循环,但似乎也加速(或至少与代码的其他部分交互)。

  • Implementing functions in C/C++: There's a bunch of Matlab/Octave functions that are implemented in Matlab/Octave. 在C / C ++中实现函数:在Matlab / Octave中实现了一堆Matlab / Octave函数。 At every release, there's a bunch more of them that get made into built-ins. 在每个版本中,都有更多的内容被制作成内置插件。

  • Multithreading: There's a list of functions that have multithreaded implementations, which will speed up function calls. 多线程:有一系列具有多线程实现的函数 ,可以加速函数调用。

  • Generally more efficient implementations. 通常更有效的实现。 For example the median filter got a massive speed boost for integer inputs a few releases ago. 例如,在几个版本之前,中值滤波器为整数输入提供了大幅度的提升。

All of these approaches need developers dedicated to make code faster. 所有这些方法都需要致力于使代码更快的开发人员。 As far as I know, a major concern of Octave developers is to make sure (Matlab) functionality is there at all, whereas performance increase seems to have been a focus of Matlab development in the last few years. 据我所知,Octave开发人员主要关心的是确保(Matlab)功能完全存在,而性能提升似乎是过去几年Matlab开发的重点。

Matlab internally uses Intel Math Kernel Library (Intel MKL) for vector and matrix operations. Matlab内部使用英特尔数学核心库(英特尔MKL)进行矢量和矩阵运算。 This gives Matlab a significant advantage over Octave. 这为Matlab提供了超越Octave的显着优势。

Try the commands 'version -lapack' and 'version -blas' in your Matlab to check the version of MKL your Matlab is using. 在Matlab中尝试使用命令'version -lapack'和'version -blas'来检查Matlab正在使用的MKL版本。

A quick link which discuss the usage of MKL by Matlab is http://stanford.edu/~echu508/matlab.html . 通过Matlab讨论MKL用法的快速链接是http://stanford.edu/~echu508/matlab.html

Intel MKL is proprietary. 英特尔MKL是专有的。 software.intel.com/en-us/intel-mkl . software.intel.com/en-us/intel-mkl。 However, for non-commercial use, the Linux version is free. 但是,对于非商业用途,Linux版本是免费的。 If Octave can somehow use the MKL installed on our machines, it should significantly speed up Octave. 如果Octave可以某种方式使用我们机器上安装的MKL,它应该可以显着加快Octave的速度。

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

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