pandas sort_values is ~13.43× slower than polars sort for sorting 400,000 floats
A single float column, ascending.
Result
| Run | pandas sort_values | polars sort | Ratio |
|---|---|---|---|
| Run 1 | 194.02 | 14.44 | 13.43× |
| Run 2 | 199.26 | 15.04 | 13.25× |
| Run 3 | 193.95 | 14.23 | 13.63× |
Spread over 3 runs: pandas sort_values CV 1.6% / polars sort CV 2.9% / ratio CV 1.4%
The two calls
df.sort_values('v') df.sort('v') Conditions
Random floats, 400,000 rows.
Where this number does not apply
A nearly sorted column changes the algorithm and the ratio.
Reproduce
cd bench && python run.py --run 1 --out ../data/run1.json