Why the same function is taking more time after MEX creation?

조회 수: 1 (최근 30일)
JAI PRAKASH
JAI PRAKASH 2018년 8월 27일
편집: Ryan Livingston 2018년 8월 29일
I want to create mex of 'sort()' funtion.
So I build below function
function idx = sort2(h) % h is 600x1280 'single' elements
[~,idx] = sort(h(:)); % because I just want indices only, I dont want the elements.
end
If I call above funtion:
Why the 'MEX' is taking more time??

채택된 답변

Ryan Livingston
Ryan Livingston 2018년 8월 28일
편집: Ryan Livingston 2018년 8월 29일
The MATLAB Coder documentation has a section covering acclerating MATLAB code via MEX generation:
One page that's relevant to what you are seeing is:
It contains the statement:
Use MEX functions to accelerate MATLAB code only if user-generated code dominates the run time.
Avoid generating MEX functions if computationally intensive, built-in MATLAB functions dominate the run time. These functions are pre-compiled and optimized, so the MATLAB code is not accelerated significantly using a MEX function.
In MATLAB, sort is a built-in function that is hand-optimized and compiled. So the generated code likely won't be any faster and can be slower in some cases.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by