3 ms·
I think that’s still affected by speculative execution. The CPU will process the step ahead assuming that a[i] != b[i] while it is doing the a[i] XOR b[i] check
by sjducb 3y ago
I think that’s still affected by speculative execution. The CPU will process the step ahead assuming that a[i] != b[i] while it is doing the a[i] XOR b[i] check.
So it’ll be faster if: most characters match, most characters don’t match or there are runs of matching characters.
Have a read of this: https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array https://stackoverflow.com/questions/11227809/why-is-processi...
- Ar-Curunir 3y agoThere is no branch here, so nothing for the CPU to speculate on.
- bluGill 3y agoThere is no obvious branch, but the compiler is allowed to implement the as-if rule and insert a branch if it figures out what you are doing.