Good question. I’m not sure why the compiler doesn’t remove the bounds check here, or why the difference is bigger on your computer. But, yes, I prefer explicit @inbounds
notation, even though it’s a bit ‘cluttery’.
1 Like
The performance difference between checked and unchecked bounds comes from the compiler inability to unroll and/or vectorize the loops with bounds checks. If the program does not benefit from those, there would be no difference except for maybe very short loops (the bound check would be “eliminated” by the branch prediction).
So, the performance gains depend on the SIMD instructions supported by the processor, memory speed etc.
1 Like