From my own tests with similar code (compiled under gcc and Linux), operator[] can be noticeably faster than at , and not because of border checks, but because of the overhead of handling exceptions. Replacing at (which throws an exception on extraordinary borders) with checking my own boundaries, which raised assert to out-bounds, gave a measurable improvement.
Using the link, as Cristo said , you can only perform an overhead check once.
Ignoring bounds checking and exception handling overhead, both operator[] and at should be optimized to equivalent direct array access or direct access with a pointer.
As Chris Becke said, there is no substitute for profiling.
Josh Kelley Apr 05 2018-10-05T00: 00Z
source share