8× faster binary search: from compiled code to mechanical sympathy

A post showing how to speed up binary search by working with the CPU.

Author
Itamar Turner-Trauring
Published
11 July 2026 (last updated 18 July 2026)
Kind
Company blog post with a worked, benchmarked Rust example
Original
pythonspeed.com/articles/branchless-binary-search/
Subject
Systems and hardware
Themes
Close to the machine

What it is

Itamar Turner-Trauring wrote this for the Python Speed site. The post comes from work done at Quansight on scikit-learn. It teaches mechanical sympathy, meaning code written to suit how the CPU runs it.

What it says

What evidence it gives

The post gives full Rust code for four versions. Tables list time, instructions, branches, misprediction rate and instructions per cycle. All numbers come from one test of 1,000,000 random values and evenly spaced boundaries.

Interests and limits

The author sells a Python performance book and consulting through the site. The tests use one synthetic data set and the post names no CPU. The final code is a simplified Rust example, not the scikit-learn change itself. The post admits it only briefly introduces low-level topics.

Connections

These links are this wiki's own reading, not claims the sources make.