MATLAB: Does the MATLAB file script/function execute slower when passed to MATLAB using the standard input as opposed to when it is called from the MATLAB command prompt

MATLAB

When I enter the following at a Linux command shell:
matlab <filename.m
it takes longer to execute than opening MATLAB and executing the following code at the MATLAB command prompt
filename

Best Answer

This is the expected behavior. Passing a file to MATLAB through the standard input executes each line of the file at the command line and does not take advantage of the JIT.
To work around this issue, use the '-r' flag when calling MATLAB to pass a file to MATLAB which will cause the file to be executed as a script/function. For example,
matlab -r filename