I have a Matlab program which calls a mex function (consuming the largest portion of my program time according to the profiler). I have its C++ code (I generated the mex one on my machine). My problem is that I call this function over 500000 times in my code, and with many runs, it makes my code need over 24 hours to be run. Adding that I need many configurations to be checked, you can imagine the situation I am trapped in. Could anyone suggest how to generate a faster mex file?