5 ms·
Yep realized this after that my second solution (push a 0 if n is incremented) has the same branch prediction problem. I think yours works. Alternatively in th
by returningfory2 1mo ago
Yep realized this after that my second solution (push a 0 if n is incremented) has the same branch prediction problem.
I think yours works. Alternatively in the loop:
if out.len() < n {
out.push(0);
}
out[n] = x;
n += (x > threshold) as usize;
In this case the if will be predicted well because it only triggers log(N) times, given how the std lib extends vectors.