pandas sort_values(2 keys) is ~13.33× slower than polars sort(2 keys) for sorting by two keys
Integer key ascending, float key descending.
Result
| Run | pandas sort_values(2 keys) | polars sort(2 keys) | Ratio |
|---|---|---|---|
| Run 1 | 294.22 | 23.43 | 12.56× |
| Run 2 | 304.7 | 22.19 | 13.73× |
| Run 3 | 321.81 | 24.14 | 13.33× |
Spread over 3 runs: pandas sort_values(2 keys) CV 4.5% / polars sort(2 keys) CV 4.3% / ratio CV 4.5%
The two calls
df.sort_values(['g','v'], ascending=[True, False]) df.sort(['g','v'], descending=[False, True]) Conditions
1,000 distinct integer keys with many ties.
Where this number does not apply
With more keys the tie-breaking cost dominates and the ratio moves.
Reproduce
cd bench && python run.py --run 1 --out ../data/run1.json