Dataframe BenchMEASURED IN ONE ENVIRONMENT

    ↑↓ to select, Enter to open, Esc to close

    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

    Runpandas sort_values(2 keys)polars sort(2 keys)Ratio
    Run 1294.2223.4312.56×
    Run 2304.722.1913.73×
    Run 3321.8124.1413.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