Simple, compiled "Hello, World" function takes 3 seconds to execute? Why so slow?
7 ビュー (過去 30 日間)
古いコメントを表示
I am attempting to compile a matlab function into an executable that I can eventually call from LabVIEW (I avoided DLLs because I was having trouble writing a wrapper function to handle data types). In the future I plan to call much more complicated functions, but for now, as a proof of concept I wrote a simple Hello World function:
function helloworld
fprintf('Hello, World!\n')
end
I compiled it using the Deployment Tool and I get an executable that takes about 5 or 6 seconds to run the first time and then about 3 seconds to run each time after that. This 3 seconds is not changed if I am calling it straight from the command line, or from the built in LabVIEW functions.
Also, if I call the function helloworld in the Matlab command line, the results are printed instantaneously, as I would expect.
Does anyone know why this might be happening? Is Matlab assumed to have this huge overhead? My end goal is to call an executable once a second. What am I missing?
I'm using compiler v4.13 R(2010a)
Thanks in Advance!
-Aaron
0 件のコメント
回答 (3 件)
Kaustubha Govind
2011 年 4 月 8 日
My guess is that the time taken is for the MATLAB Compiler Runtime to startup, execute the command via the MATLAB interpreter libraries and then shutdown. Since you want to call it every 1 second, MATLAB Compiler does not seem the right choice for your application. MATLAB Coder (new in R2011a) should be the right product to use - you can generate standalone C/C++ code from MATLAB code, provided that you are using the supported MATLAB language features in your code.
If you are using an older release, the same functionality was available using the Embedded MATLAB feature (need Real-Time Workshop license).
0 件のコメント
Jiro Doke
2011 年 4 月 8 日
Kaustubha's explanation about MATLAB Compiler Runtime (MCR) is correct. The runtime is essentially MATLAB (without the desktop and interface). When you call the function from MATLAB commandline, MATLAB is already open, so that's why it's fast. If you run the deployed application from the operating system (or elsewhere), then it has to first launch MCR.
MATLAB Coder is one option, but another option is to create a shared library from MATLAB Compiler. If you can call DLL's from LabVIEW, then you can set it up so that you initialize MCR once in the beginning, call the MATLAB routine (via library) as many time as you want, and then terminate MCR at the end.
0 件のコメント
Mohammad
2011 年 4 月 9 日
Additionally you can convert some codes manually to other languages
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!