The "end" statement itself does not take any time, but when MATLAB needs some time to do internal operations for the loop, the time is sometimes marked as being on the "end" because it is not really directly associated with the other lines.
You should, in particular, pre-allocate any arrays that you write inside of. However, arrays that you overwrite completely without any subscripts, do not need to be preallocated.
clearing variables before the end of the loop is, in most cases, not necessary and could slow you down. There are some cases where it helps.
Best Answer