Given the following code (and with optimisations on):
pub fn no_assert(input: &mut [u8]) {
for i in 0..10 {
input[i] += input[i+1];
}
}
pub fn with_assert(input: &mut [u8]) {
assert!(input.len() >= 11);
for i in 0..10 {
input[i] += input[i+1];
}
}
The no_assert function ends up doing a bounds check for every iteration, and the with_assert function only does a single check.