Which kind of mex implementation is faster? C++ to mex file or .m function to mex

2 ビュー (過去 30 日間)
I have a function in my code which consumes almost 80% of the total run time. I converted this .m function into mex file through coder function which significantly improved the speed but my code is still not real-time. I am working on video processing and its kind of a requirement that my code should perform real-time operations. I am wondering if I implement the whole function in C++ and create a mex file from that, will it improve the speed? I need guidance regarding the technical differences between a mex file converted from matlab .m function and a mex file converted from C++ function.

採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 2 日
A mex file created from MATLAB code is automatically generated code in the target language. It cannot do anything that hand-written code could not do. It might take advantage of libraries, but you could call the same libraries.
The automatically generated code has some advantages in perhaps being easier to automatically test for use with MATLAB.
The biggest advantage of the automatically generated code is that it saves you from a lot of tedium and typos, and from having to know as much about C++.
For some patterns it might be hard to beat the automatically generated code with hand-written code, because hand-written code for vector operations is often less efficient than calling into a high performance library.
If you need real-time work you should be considering using Simulink with Fixed Point Designer and HDL Coder to generate a FPGA or chip; or you should consider using Simulink Real-Time to generate code for a true Real-Time operating system.
MS Windows is never a Real-Time operating system. There are real-time versions of Linux, and it can be easier to control performance in Linux. There are also "harder" real-time operating system devoted to ensuring that everything takes a planned amount of time.
MATLAB itself makes no attempt to be Real Time: it is only hosted on general-purpose operating systems that are not real-time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by