- Published on
Investigation · Part 17 of 20 · When the benchmark lies
Why Sorted Data Can Make the Same Loop Faster
The famous result says that a loop over sorted data is faster because of branch prediction. In my Rust version, sorting changed nothing, because the compiler removed the branch. With a branch that it could not remove, random data was 3 to 10 times slower.