简体   繁体   中英

MATLAB executable is too slow

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.

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.

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.

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/

Just as an addition to everything said above, may I suggest setting up a RAM drive, and setting MCR_CACHE_ROOT system variable to a directory on a RAM drive.

This will significantly improve further startup times.

Make sure your RAM drive is persistent during reboots, if anyone uses this scheme on a desktop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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