You have observed it correctly.
When you execure a PIL MEX at a high level below things will happen :
- Marshall the input data from MATLAB to C/C++
- Establish communication with the actual processor (hardware)
- Execute the code in processor
- Marshall back the results from C/C++ to MATLAB
So the tic toc will measure the time taken by all these events.
On the otherhand the profiler will capture only the actual execution time in the processor using the instrumenting techniques.
So the profiler data will give you some estimation of the actual exectuion time if you were to deploy the code to the hardware and execute natively in that hardware.
I have created a similar example for SIL execution time. I my machine below are the timing data :
Time taken by SIL using tic-toc : 5.2 ms
Profiler exection time (Average) : 0.6 ms
I hope this helps.