为什么我在使用MATLAB编译器时没有看到显着的加速?

时间:2022-09-20 13:58:21

I have a lot of nice MATLAB code that runs too slowly and would be a pain to write over in C. The MATLAB compiler for C does not seem to help much, if at all. Should it be speeding execution up more? Am I screwed?

我有很多很好的MATLAB代码,运行速度太慢,用C语言编写是很痛苦的。用于C的MATLAB编译器似乎没有多大帮助,如果有的话。它应该加快执行速度吗?我搞砸了吗?

11 个解决方案

#1


14  

I'll echo what dwj said: if your MATLAB code is slow, this is probably because it is not sufficiently vectorized. If you're doing explicit loops when you could be doing operations on whole arrays, that's the culprit.

我会回应dwj所说的:如果你的MATLAB代码很慢,这可能是因为它没有足够的矢量化。如果您在对整个数组进行操作时进行显式循环,那就是罪魁祸首。

This applies equally to all array-oriented dynamic languages: Perl Data Language, Numeric Python, MATLAB/Octave, etc. It's even true to some extent in compiled C and FORTRAN compiled code: specially-designed vectorization libraries generally use carefully hand-coded inner loops and SIMD instructions (e.g. MMX, SSE, AltiVec).

这同样适用于所有面向阵列的动态语言:Perl数据语言,数字Python,MATLAB / Octave等。在编译的C和FORTRAN编译代码中甚至有一定程度的真实:专门设计的矢量化库通常使用仔细的手工编码内部循环和SIMD指令(例如MMX,SSE,AltiVec)。

#2


22  

If you are using the MATLAB complier (on a recent version of MATLAB) then you will almost certainly not see any speedups at all. This is because all the compiler actually does is give you a way of packaging up your code so that it can be distributed to people who don't have MATLAB. It doesn't convert it to anything faster (such as machine code or C) - it merely wraps it in C so you can call it.

如果您正在使用MATLAB编译器(在最新版本的MATLAB上),那么您几乎肯定不会看到任何加速。这是因为所有编译器实际上都是为您提供了一种打包代码的方法,以便将其分发给没有MATLAB的人。它不会将它转换为更快的任何东西(例如机器代码或C) - 它只是将它包装在C中,因此您可以调用它。

It does this by getting your code to run on the MATLAB Compiler Runtime (MCR) which is essentially the MATLAB computational kernel - your code is still being interpreted. Thanks to the penalty incurred by having to invoke the MCR you may find that compiled code runs more slowly than if you simply ran it on MATLAB.

它通过让您的代码在MATLAB编译器运行时(MCR)上运行来实现这一点,该运行时基本上是MATLAB计算内核 - 您的代码仍在被解释。由于必须调用MCR而导致的惩罚,您可能会发现编译代码的运行速度比在MATLAB上运行它时要慢。

Put another way - you might say that the compiler doesn't actually compile - in the traditional sense of the word at least.

换句话说 - 你可能会说编译器实际上没有编译 - 至少在传统意义上说。

Older versions of the compiler worked differently and speedups could occur in certain situations. For Mathwork's take on this go to

较旧版本的编译器工作方式不同,在某些情况下可能会出现加速。对于Mathwork来说,这是一个很好的选择

http://www.mathworks.com/support/solutions/data/1-1ARNS.html

#3


19  

In my experience slow MATLAB code usually comes from not vectorizing your code (i.e., writing for-loops instead of just multiplying arrays (simple example)).

根据我的经验,缓慢的MATLAB代码通常来自不对代码进行矢量化(即,编写for循环而不仅仅是乘法数组(简单示例))。

If you are doing file I/O look out for reading data in one piece at a time. Look in the help files for the vectorized version of fscanf.

如果您正在进行文件I / O,请注意一次读取一个数据。查看fscanf矢量化版本的帮助文件。

Don't forget that MATLAB includes a profiler, too!

不要忘记MATLAB也包含一个分析器!

#4


5  

First, I second all the above comments about profiling and vectorizing.

首先,我首先回顾有关分析和矢量化的所有上述评论。

For a historical perspective...

从历史的角度来看......

Older version of Matlab allowed the user to convert m files to mex functions by pre-parsing the m code and converting it to a set of matlab library calls. These calls have all the error checking that the interpreter did, but old versions of the interpreter and/or online parser were slow, so compiling the m file would sometimes help. Usually it helped when you had loops because Matlab was smart enough to inline some of that in C. If you have one of those versions of Matlab, you can try telling the mex script to save the .c file and you can see exactly what it's doing.

旧版本的Matlab允许用户通过预解析m代码并将其转换为一组matlab库调用,将m个文件转换为mex函数。这些调用具有解释器所做的所有错误检查,但旧版本的解释器和/或在线解析器速度很慢,因此编译m文件有时会有所帮助。通常它有助于你有循环,因为Matlab很聪明,可以在C中内联其中一些。如果你有其中一个版本的Matlab,你可以尝试告诉mex脚本保存.c文件,你可以看到它的确切内容这样做。

In more recent version (probably 2006a and later, but I don't remember), Mathworks started using a just-in-time compiler for the interpreter. In effect, this JIT compiler automatically compiles all mex functions, so explicitly doing it offline doesn't help at all. In each version since then, they've also put a lot of effort into making the interpreter much faster. I believe that newer versions of Matlab don't even let you automatically compile m files to mex files because it doesn't make sense any more.

在更新的版本中(可能是2006a及更高版本,但我不记得了),Mathworks开始为解释器使用即时编译器。实际上,这个JIT编译器会自动编译所有mex函数,因此显式脱机操作根本没有帮助。在那之后的每个版本中,他们也花了很多精力使解释器更快。我相信更新版本的Matlab甚至不允许你自动将m文件编译为mex文件,因为它没有任何意义。

#5


3  

The MATLAB compiler wraps up your m-code and dispatches it to a MATLAB runtime. So, the performance you see in MATLAB should be the performance you see with the compiler.

MATLAB编译器包装您的m代码并将其分派给MATLAB运行时。因此,您在MATLAB中看到的性能应该是您在编译器中看到的性能。

Per the other answers, vectorizing your code is helpful. But, the MATLAB JIT is pretty good these days and lots of things perform roughly as well vectorized or not. That'a not to say there aren't performance benefits to be gained from vectorization, it's just not the magic bullet it once was. The only way to really tell is to use the profiler to find out where your code is seeing bottlenecks. Often times there are some places where you can do local refactoring to really improve the performance of your code.

根据其他答案,矢量化代码很有帮助。但是,MATLAB JIT现在相当不错,很多东西的表现大致与矢量化或不同。这并不是说从矢量化中获得的性能优势,它不仅仅是曾经的神奇子弹。真正告诉的唯一方法是使用分析器来找出代码看到瓶颈的位置。通常情况下,有些地方可以进行本地重构,以真正提高代码的性能。

There are a couple of other hardware approaches you can take on performance. First, much of the linear algebra subsystem is multithreaded. You may want to make sure you have enabled that in your preferences if you are working on a multi-core or multi-processor platform. Second, you may be able to use the parallel computing toolbox to take more advantage of multiple processors. Finally, if you are a Simulink user, you may be able to use emlmex to compile m-code into c. This is particularly effective for fixed point work.

您可以采用其他几种硬件方法来提高性能。首先,大部分线性代数子系统都是多线程的。如果您正在使用多核或多处理器平台,则可能需要确保已在首选项中启用了该功能。其次,您可以使用并行计算工具箱来充分利用多个处理器。最后,如果您是Simulink用户,您可以使用emlmex将m代码编译为c。这对定点工作特别有效。

#6


2  

Have you tried profiling your code? You don't need to vectorize ALL your code, just the functions that dominate running time. The MATLAB profiler will give you some hints on where your code is spending the most time.

您是否尝试过分析代码?您不需要对所有代码进行矢量化,只需要控制运行时间的函数。 MATLAB探查器将为您提供有关代码花费最多时间的一些提示。

There are many other things you you should read up on the Tips For Improving Performance section in the MathWorks manual.

您还应该阅读MathWorks手册中的“提高性能提示”部分中的许多其他内容。

#7


1  

mcc won't speed up your code at all--it's not really a compiler.

mcc根本不会加速你的代码 - 它不是真正的编译器。

Before you give up, you need to run the profiler and figure out where all your time is going (Tools->Open Profiler). Also, judicious use of "tic" and "toc" can help. Don't optimize your code until you know where the time is going (don't try to guess).

在放弃之前,您需要运行探查器并找出所有时间的位置(工具 - >打开Profiler)。此外,明智地使用“tic”和“toc”可以提供帮助。在知道时间到来之前不要优化代码(不要试图猜测)。

Keep in mind that in matlab:

请记住,在matlab中:

  • bit-level operations are really slow
  • 位级操作真的很慢

  • file I/O is slow
  • 文件I / O很慢

  • loops are generally slow, but vectorizing is fast (if you don't know the vector syntax, learn it)
  • 循环通常很慢,但矢量化很快(如果您不知道矢量语法,请学习它)

  • core operations are really fast (e.g. matrix multiply, fft)
  • 核心操作非常快(例如矩阵乘法,fft)

  • if you think you can do something faster in C/Fortran/etc, you can write a MEX file
  • 如果你认为你可以在C / Fortran / etc中做得更快,你可以写一个MEX文件

  • there are commercial solutions to convert matlab to C (google "matlab to c") and they work
  • 有商业解决方案将matlab转换为C(谷歌“matlab到c”),他们的工作

#8


1  

You could port your code to "Embedded Matlab" and then use the Realtime-Workshop to translate it to C.

您可以将代码移植到“Embedded Matlab”,然后使用Realtime-Workshop将其转换为C.

Embedded Matlab is a subset of Matlab. It does not support Cell-Arrays, Graphics, Marices of dynamic size, or some Matrix addressing modes. It may take considerable effort to port to Embedded Matlab.

嵌入式Matlab是Matlab的一个子集。它不支持单元阵列,图形,动态大小的Marice或某些Matrix寻址模式。移植到嵌入式Matlab可能需要相当大的努力。

Realtime-Workshop is at the core of the Code Generation Products. It spits out generic C, or can optimize for a range of embedded Platforms. Most interresting to you is perhaps the xPC-Target, which treats general purpose hardware as embedded target.

Realtime-Workshop是代码生成产品的核心。它吐出通用C,或者可以针对一系列嵌入式平台进行优化。对您而言最令人感兴趣的可能是xPC-Target,它将通用硬件视为嵌入式目标。

#9


1  

I would vote for profiling + then look at what are the bottlenecks.

我会投票分析+然后看看瓶颈是什么。

If the bottleneck is matrix math, you're probably not going to do any better... EXCEPT one big gotcha is array allocation. e.g. if you have a loop:

如果瓶颈是矩阵数学,你可能不会做得更好......除了一个大问题是数组分配。例如如果你有一个循环:

s = [];
for i = 1:50000
  s(i) = 3;
end

This has to keep resizing the array; it's much faster to presize the array (start with zeros or NaN) & fill it from there:

这必须不断调整阵列的大小;预设数组(从零或NaN开始)并从那里填充它要快得多:

s = zeros(50000,1);
for i = 1:50000
  s(i) = 3;
end

If the bottleneck is repeated executions of a lot of function calls, that's a tough one.

如果瓶颈被重复执行很多函数调用,那就很难了。

If the bottleneck is stuff that MATLAB doesn't do quickly (certain types of parsing, XML, stuff like that) then I would use Java since MATLAB already runs on a JVM and it interfaces really easily to arbitrary JAR files. I looked at interfacing with C/C++ and it's REALLY ugly. Microsoft COM is ok (on Windows only) but after learning Java I don't think I'll ever go back to that.

如果瓶颈是MATLAB不能快速做的事情(某些类型的解析,XML,那样的东西),那么我会使用Java,因为MATLAB已经在JVM上运行,并且它很容易与任意JAR文件接口。我看着与C / C ++的接口,它真的很难看。 Microsoft COM是可以的(仅限Windows),但在学习Java之后,我认为我不会再回过头来了。

#10


0  

As others has noted, slow Matlab code is often the result of insufficient vectorization.

正如其他人所指出的那样,缓慢的Matlab代码通常是矢量化不足的结果。

However, sometimes even perfectly vectorized code is slow. Then, you have several more options:

但是,有时甚至完美的矢量化代码也很慢。然后,您还有几个选项:

  1. See if there are any libraries / toolboxes you can use. These were usually written to be very optimized.
  2. 看看是否有可以使用的库/工具箱。这些通常写得非常优化。

  3. Profile your code, find the tight spots and rewrite those in plain C. Connecting C code (as DLLs for instance) to Matlab is easy and is covered in the documentation.
  4. 描述您的代码,找到紧凑的地方并重写那些简单的C.将C代码(例如DLL)连接到Matlab很容易,并在文档中介绍。

#11


-1  

By Matlab compiler you probably mean the command mcc, which does speed the code a little bit by circumventing Matlab interpreter. What would speed the MAtlab code significantly (by a factor of 50-200) is use of actual C code compiled by the mex command.

通过Matlab编译器你可能意味着命令mcc,它通过绕过Matlab解释器来加速代码。什么会显着加速MAtlab代码(50-200倍)是使用mex命令编译的实际C代码。

#1


14  

I'll echo what dwj said: if your MATLAB code is slow, this is probably because it is not sufficiently vectorized. If you're doing explicit loops when you could be doing operations on whole arrays, that's the culprit.

我会回应dwj所说的:如果你的MATLAB代码很慢,这可能是因为它没有足够的矢量化。如果您在对整个数组进行操作时进行显式循环,那就是罪魁祸首。

This applies equally to all array-oriented dynamic languages: Perl Data Language, Numeric Python, MATLAB/Octave, etc. It's even true to some extent in compiled C and FORTRAN compiled code: specially-designed vectorization libraries generally use carefully hand-coded inner loops and SIMD instructions (e.g. MMX, SSE, AltiVec).

这同样适用于所有面向阵列的动态语言:Perl数据语言,数字Python,MATLAB / Octave等。在编译的C和FORTRAN编译代码中甚至有一定程度的真实:专门设计的矢量化库通常使用仔细的手工编码内部循环和SIMD指令(例如MMX,SSE,AltiVec)。

#2


22  

If you are using the MATLAB complier (on a recent version of MATLAB) then you will almost certainly not see any speedups at all. This is because all the compiler actually does is give you a way of packaging up your code so that it can be distributed to people who don't have MATLAB. It doesn't convert it to anything faster (such as machine code or C) - it merely wraps it in C so you can call it.

如果您正在使用MATLAB编译器(在最新版本的MATLAB上),那么您几乎肯定不会看到任何加速。这是因为所有编译器实际上都是为您提供了一种打包代码的方法,以便将其分发给没有MATLAB的人。它不会将它转换为更快的任何东西(例如机器代码或C) - 它只是将它包装在C中,因此您可以调用它。

It does this by getting your code to run on the MATLAB Compiler Runtime (MCR) which is essentially the MATLAB computational kernel - your code is still being interpreted. Thanks to the penalty incurred by having to invoke the MCR you may find that compiled code runs more slowly than if you simply ran it on MATLAB.

它通过让您的代码在MATLAB编译器运行时(MCR)上运行来实现这一点,该运行时基本上是MATLAB计算内核 - 您的代码仍在被解释。由于必须调用MCR而导致的惩罚,您可能会发现编译代码的运行速度比在MATLAB上运行它时要慢。

Put another way - you might say that the compiler doesn't actually compile - in the traditional sense of the word at least.

换句话说 - 你可能会说编译器实际上没有编译 - 至少在传统意义上说。

Older versions of the compiler worked differently and speedups could occur in certain situations. For Mathwork's take on this go to

较旧版本的编译器工作方式不同,在某些情况下可能会出现加速。对于Mathwork来说,这是一个很好的选择

http://www.mathworks.com/support/solutions/data/1-1ARNS.html

#3


19  

In my experience slow MATLAB code usually comes from not vectorizing your code (i.e., writing for-loops instead of just multiplying arrays (simple example)).

根据我的经验,缓慢的MATLAB代码通常来自不对代码进行矢量化(即,编写for循环而不仅仅是乘法数组(简单示例))。

If you are doing file I/O look out for reading data in one piece at a time. Look in the help files for the vectorized version of fscanf.

如果您正在进行文件I / O,请注意一次读取一个数据。查看fscanf矢量化版本的帮助文件。

Don't forget that MATLAB includes a profiler, too!

不要忘记MATLAB也包含一个分析器!

#4


5  

First, I second all the above comments about profiling and vectorizing.

首先,我首先回顾有关分析和矢量化的所有上述评论。

For a historical perspective...

从历史的角度来看......

Older version of Matlab allowed the user to convert m files to mex functions by pre-parsing the m code and converting it to a set of matlab library calls. These calls have all the error checking that the interpreter did, but old versions of the interpreter and/or online parser were slow, so compiling the m file would sometimes help. Usually it helped when you had loops because Matlab was smart enough to inline some of that in C. If you have one of those versions of Matlab, you can try telling the mex script to save the .c file and you can see exactly what it's doing.

旧版本的Matlab允许用户通过预解析m代码并将其转换为一组matlab库调用,将m个文件转换为mex函数。这些调用具有解释器所做的所有错误检查,但旧版本的解释器和/或在线解析器速度很慢,因此编译m文件有时会有所帮助。通常它有助于你有循环,因为Matlab很聪明,可以在C中内联其中一些。如果你有其中一个版本的Matlab,你可以尝试告诉mex脚本保存.c文件,你可以看到它的确切内容这样做。

In more recent version (probably 2006a and later, but I don't remember), Mathworks started using a just-in-time compiler for the interpreter. In effect, this JIT compiler automatically compiles all mex functions, so explicitly doing it offline doesn't help at all. In each version since then, they've also put a lot of effort into making the interpreter much faster. I believe that newer versions of Matlab don't even let you automatically compile m files to mex files because it doesn't make sense any more.

在更新的版本中(可能是2006a及更高版本,但我不记得了),Mathworks开始为解释器使用即时编译器。实际上,这个JIT编译器会自动编译所有mex函数,因此显式脱机操作根本没有帮助。在那之后的每个版本中,他们也花了很多精力使解释器更快。我相信更新版本的Matlab甚至不允许你自动将m文件编译为mex文件,因为它没有任何意义。

#5


3  

The MATLAB compiler wraps up your m-code and dispatches it to a MATLAB runtime. So, the performance you see in MATLAB should be the performance you see with the compiler.

MATLAB编译器包装您的m代码并将其分派给MATLAB运行时。因此,您在MATLAB中看到的性能应该是您在编译器中看到的性能。

Per the other answers, vectorizing your code is helpful. But, the MATLAB JIT is pretty good these days and lots of things perform roughly as well vectorized or not. That'a not to say there aren't performance benefits to be gained from vectorization, it's just not the magic bullet it once was. The only way to really tell is to use the profiler to find out where your code is seeing bottlenecks. Often times there are some places where you can do local refactoring to really improve the performance of your code.

根据其他答案,矢量化代码很有帮助。但是,MATLAB JIT现在相当不错,很多东西的表现大致与矢量化或不同。这并不是说从矢量化中获得的性能优势,它不仅仅是曾经的神奇子弹。真正告诉的唯一方法是使用分析器来找出代码看到瓶颈的位置。通常情况下,有些地方可以进行本地重构,以真正提高代码的性能。

There are a couple of other hardware approaches you can take on performance. First, much of the linear algebra subsystem is multithreaded. You may want to make sure you have enabled that in your preferences if you are working on a multi-core or multi-processor platform. Second, you may be able to use the parallel computing toolbox to take more advantage of multiple processors. Finally, if you are a Simulink user, you may be able to use emlmex to compile m-code into c. This is particularly effective for fixed point work.

您可以采用其他几种硬件方法来提高性能。首先,大部分线性代数子系统都是多线程的。如果您正在使用多核或多处理器平台,则可能需要确保已在首选项中启用了该功能。其次,您可以使用并行计算工具箱来充分利用多个处理器。最后,如果您是Simulink用户,您可以使用emlmex将m代码编译为c。这对定点工作特别有效。

#6


2  

Have you tried profiling your code? You don't need to vectorize ALL your code, just the functions that dominate running time. The MATLAB profiler will give you some hints on where your code is spending the most time.

您是否尝试过分析代码?您不需要对所有代码进行矢量化,只需要控制运行时间的函数。 MATLAB探查器将为您提供有关代码花费最多时间的一些提示。

There are many other things you you should read up on the Tips For Improving Performance section in the MathWorks manual.

您还应该阅读MathWorks手册中的“提高性能提示”部分中的许多其他内容。

#7


1  

mcc won't speed up your code at all--it's not really a compiler.

mcc根本不会加速你的代码 - 它不是真正的编译器。

Before you give up, you need to run the profiler and figure out where all your time is going (Tools->Open Profiler). Also, judicious use of "tic" and "toc" can help. Don't optimize your code until you know where the time is going (don't try to guess).

在放弃之前,您需要运行探查器并找出所有时间的位置(工具 - >打开Profiler)。此外,明智地使用“tic”和“toc”可以提供帮助。在知道时间到来之前不要优化代码(不要试图猜测)。

Keep in mind that in matlab:

请记住,在matlab中:

  • bit-level operations are really slow
  • 位级操作真的很慢

  • file I/O is slow
  • 文件I / O很慢

  • loops are generally slow, but vectorizing is fast (if you don't know the vector syntax, learn it)
  • 循环通常很慢,但矢量化很快(如果您不知道矢量语法,请学习它)

  • core operations are really fast (e.g. matrix multiply, fft)
  • 核心操作非常快(例如矩阵乘法,fft)

  • if you think you can do something faster in C/Fortran/etc, you can write a MEX file
  • 如果你认为你可以在C / Fortran / etc中做得更快,你可以写一个MEX文件

  • there are commercial solutions to convert matlab to C (google "matlab to c") and they work
  • 有商业解决方案将matlab转换为C(谷歌“matlab到c”),他们的工作

#8


1  

You could port your code to "Embedded Matlab" and then use the Realtime-Workshop to translate it to C.

您可以将代码移植到“Embedded Matlab”,然后使用Realtime-Workshop将其转换为C.

Embedded Matlab is a subset of Matlab. It does not support Cell-Arrays, Graphics, Marices of dynamic size, or some Matrix addressing modes. It may take considerable effort to port to Embedded Matlab.

嵌入式Matlab是Matlab的一个子集。它不支持单元阵列,图形,动态大小的Marice或某些Matrix寻址模式。移植到嵌入式Matlab可能需要相当大的努力。

Realtime-Workshop is at the core of the Code Generation Products. It spits out generic C, or can optimize for a range of embedded Platforms. Most interresting to you is perhaps the xPC-Target, which treats general purpose hardware as embedded target.

Realtime-Workshop是代码生成产品的核心。它吐出通用C,或者可以针对一系列嵌入式平台进行优化。对您而言最令人感兴趣的可能是xPC-Target,它将通用硬件视为嵌入式目标。

#9


1  

I would vote for profiling + then look at what are the bottlenecks.

我会投票分析+然后看看瓶颈是什么。

If the bottleneck is matrix math, you're probably not going to do any better... EXCEPT one big gotcha is array allocation. e.g. if you have a loop:

如果瓶颈是矩阵数学,你可能不会做得更好......除了一个大问题是数组分配。例如如果你有一个循环:

s = [];
for i = 1:50000
  s(i) = 3;
end

This has to keep resizing the array; it's much faster to presize the array (start with zeros or NaN) & fill it from there:

这必须不断调整阵列的大小;预设数组(从零或NaN开始)并从那里填充它要快得多:

s = zeros(50000,1);
for i = 1:50000
  s(i) = 3;
end

If the bottleneck is repeated executions of a lot of function calls, that's a tough one.

如果瓶颈被重复执行很多函数调用,那就很难了。

If the bottleneck is stuff that MATLAB doesn't do quickly (certain types of parsing, XML, stuff like that) then I would use Java since MATLAB already runs on a JVM and it interfaces really easily to arbitrary JAR files. I looked at interfacing with C/C++ and it's REALLY ugly. Microsoft COM is ok (on Windows only) but after learning Java I don't think I'll ever go back to that.

如果瓶颈是MATLAB不能快速做的事情(某些类型的解析,XML,那样的东西),那么我会使用Java,因为MATLAB已经在JVM上运行,并且它很容易与任意JAR文件接口。我看着与C / C ++的接口,它真的很难看。 Microsoft COM是可以的(仅限Windows),但在学习Java之后,我认为我不会再回过头来了。

#10


0  

As others has noted, slow Matlab code is often the result of insufficient vectorization.

正如其他人所指出的那样,缓慢的Matlab代码通常是矢量化不足的结果。

However, sometimes even perfectly vectorized code is slow. Then, you have several more options:

但是,有时甚至完美的矢量化代码也很慢。然后,您还有几个选项:

  1. See if there are any libraries / toolboxes you can use. These were usually written to be very optimized.
  2. 看看是否有可以使用的库/工具箱。这些通常写得非常优化。

  3. Profile your code, find the tight spots and rewrite those in plain C. Connecting C code (as DLLs for instance) to Matlab is easy and is covered in the documentation.
  4. 描述您的代码,找到紧凑的地方并重写那些简单的C.将C代码(例如DLL)连接到Matlab很容易,并在文档中介绍。

#11


-1  

By Matlab compiler you probably mean the command mcc, which does speed the code a little bit by circumventing Matlab interpreter. What would speed the MAtlab code significantly (by a factor of 50-200) is use of actual C code compiled by the mex command.

通过Matlab编译器你可能意味着命令mcc,它通过绕过Matlab解释器来加速代码。什么会显着加速MAtlab代码(50-200倍)是使用mex命令编译的实际C代码。