Compiling with Matlab instead of interpreting

9 views (last 30 days)
Hi,
I'm looking to compare different coding software (Matlab, Python and Labview) to know which one would be the most adept for my need. I wanted to write the same heavy calculations in the three language and see which one runs faster. I would be making a custom function and calling it a hundred times and see how long it took to execute.
To do so, I wanted to optimize my code the best I can. To my understanding, Matlab is an interpreter. He will go line by line traducting the code for the computer to execute it. I wanted to know if it was possible to compile the code in advance in a way to make it execute as fast as a compiler.
Thank you
RMT

Accepted Answer

Bruno Luong
Bruno Luong on 12 Nov 2018
Edited: Bruno Luong on 12 Nov 2018
MATLAB calls FFTW library behind the scene, so if you are doing heavily FFT for convolution, there is not much speed penalty.
I recently code an algorithm in C and invokes FFTW; I can attest it's pretty hard to beat MATLAB.
It hard to say anything about speed. It depends not only which "language" you select but also where as you are beginer or expert.
In MATLAB, it can play a great role.
  9 Comments
Raphaël
Raphaël on 13 Nov 2018
Just making sure I studied all my options.
I'll most likelly do the calibration part of my code in Matlab since it only need to run the function once, time is far less of an issue, it's the most computation heavy and it's already written in Matlab.
Bruno Luong
Bruno Luong on 13 Nov 2018
You need to pay attention to threading.
Labview is heavily multi-thread and MATLAB is mostly not threadsafe. That can create serious locking if you call stuff asynchronuously..

Sign in to comment.

More Answers (2)

Matt J
Matt J on 12 Nov 2018
With some limitations, you can convert Matlab code to C using the Matlab Coder and compile that.
  2 Comments
Raphaël
Raphaël on 12 Nov 2018
Do you have an idea for the limitations? I'm using fast fourrier transform and 3D convolution functions in my code.
Matt J
Matt J on 13 Nov 2018
Edited: Matt J on 13 Nov 2018
Here are a few relevant links.
But I agree with Bruno. It's going to be hard to beat ordinary Matlab at FFT and convolution operations, especially if you do those computations on the GPU using the Parallel Computing Toolbox.

Sign in to comment.


Image Analyst
Image Analyst on 12 Nov 2018
  1 Comment
Bruno Luong
Bruno Luong on 12 Nov 2018
MATLAB compiler actually doesn't compile anything. It just encrypt/package the source code to run under the runtime.
In this perspective, the speed gain is 0.

Sign in to comment.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!