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.