How much faster is the branchless version in practice? I make heavy use of binary search in some code I maintain, and I wonder if it would make much of a difference to switch to a more efficient version of the function.
How much faster is the branchless version in practice? I make heavy use of binary search in some code I maintain, and I wonder if it would make much of a difference to switch to a more efficient version of the function.
old branchless version: https://github.com/rust-lang/rust/pull/45333/files
I see (left+right)/2. Is it like python with unbounded precision?
Where do you see that in the code? I can't see (left+right)/2 anywhere in the code I linked?
No, it uses 2’s complement and is well defined in release mode. From [1]:
> When you’re compiling in release mode with the --release flag, Rust does not include checks for integer overflow that cause panics. Instead, if overflow occurs, Rust performs two’s complement wrapping.
[1]: https://doc.rust-lang.org/book/ch03-02-data-types.html#integ...
This array would not fit in any kind of memory for the foreseeable future :)
https://doc.rust-lang.org/nightly/rustc/platform-support.htm...
[1]: https://doc.rust-lang.org/stable/reference/types/numeric.htm...
There is no (left+right)/2 on that page.
let mid = left + size / 2;
It's only size that is being divided by 2, which is the size of the segment still under consideration (which is initially the whole array). left is the starting index of segment still under consideration (which is initially 0).