MATLAB executable is too slow

主宰稳场 提交于 2019-11-26 16:27:11

问题


I converted my MATLAB program into a console-based application using the deploytool in MATLAB. The MATLAB .m file takes around 2 seconds to execute, but after I converted it into an executable and called the .exe, it takes 45 seconds to execute which is too long.

I want to integrate the MATLAB program with PHP. Is there another efficient and fast way to do this? In my project, time is really a big factor (not the developing time but the execution time of the application). So is there a method that takes less time?

I saw on the Internet that we can write PHP extensions to call the MATLAB. Is this method fast or the same as calling the .exe file? Is a MATLAB coder any help for this process? If there is an alternative option, please mention it.


回答1:


A MATLAB compiled .exe will suffer from overhead at the first time you run it becuase it is starting the MCR: Why does my application compiled with the MATLAB Compiler 4.1 take a long time to start up?

Unless you log off or restart your OS, the MCR will remain pre-loaded. Another useful read: Speeding up compiled apps startup.

"Why does my stand-alone created using the MATLAB Compiler take longer to start the first time?" also reports that consecutive runs should be faster, but if you rerun later, you will have to reload the process in memory.

You can enclose your code within tic toc, deploy it and check how much time the execution is taking, against startup overhead.

The alternative to speeding up the .exe would be to call MATLAB with PHP. If you keep the MATLAB session open you run into the overhead once. You could launch MATLAB at startup, thus avoiding to suffer the overhead specifically during the call with PHP.

For more info read Calling MATLAB from PHP, and keep in mind that you don't want to use exit unless specifically needed.




回答2:


Calling an executable created with MATLAB Compiler will suffer an overhead relative to calling the program within live MATLAB, as it needs to start the MCR. This will be longer the first time you start it, but there will still be an overhead even after the first time.

If you have access not only to MATLAB Compiler, but to one of the Builder products (Builder for .NET or - which is probably better since you're using PHP - Builder for Java) there is a way of working around this.

Using the Builder products you can create a standalone component (either a .NET assembly or a Java .jar). You can then create a .NET or Java application that will run, instantiate your MATLAB-built component - which starts the MCR - and then sit there and wait for a call from your PHP. Each call will then not suffer the MCR startup overhead at all, and should only have a much smaller overhead from the call from PHP to .NET/Java.




回答3:


As others said, when you call the executables, there a (really big for matlab) overhead when the executable is loaded. The solution? Load it only one time. How to do it? It's complicated and depend on the platforms.

I think that the most portable way to do somethings like it is to make a server in matlab (I know this is possible, but I never tried). So when you need to use it, you simply connect to it and send the arguments.

Take a look at this: HTTP server in matlab and this: http://blogs.mathworks.com/loren/2011/05/27/transferring-data-between-two-computers-using-matlab/



来源:https://stackoverflow.com/questions/15967157/matlab-executable-is-too-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!