Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB executable is too slow

Tags:

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.

like image 560
user1583647 Avatar asked Apr 12 '13 09:04

user1583647


People also ask

Why is MATLAB being so slow?

MATLAB may be running slowly because you have a limited amount of RAM (i.e. under 128MB). The RAM used by MATLAB at runtime is between 40MB-60MB. The HELP browser can take up another 12MB. If you have limited memory (RAM), your processor may start using virtual memory (from your hard drive).

What is MATLAB Coder?

MATLAB Coder™ generates C and C++ code from MATLAB® code for a variety of hardware platforms, from desktop systems to embedded hardware. It supports most of the MATLAB language and a wide range of toolboxes. You can integrate the generated code into your projects as source code, static libraries, or dynamic libraries.

Can I install two MATLAB versions?

It is possible to have multiple MATLAB installations on the same computer. Be sure to install each version in a different directory.

What is MATLAB production server?

MATLAB Production Server™ is an application server that lets you publish MATLAB® functions as APIs that can be called from enterprise applications. MATLAB Production Sever is scalable, secure, and easily managed. It acts as an integration point between MATLAB code, data sources, and third-party applications.


2 Answers

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.

like image 74
Oleg Avatar answered Sep 27 '22 20:09

Oleg


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.

like image 42
Sam Roberts Avatar answered Sep 27 '22 20:09

Sam Roberts