Dataframe BenchMEASURED IN ONE ENVIRONMENT

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

    pandas mask + sort_values is ~6.54× slower than polars filter + sort for filtering then sorting

    Two operations chained, timed as one.

    Result

    Runpandas mask + sort_valuespolars filter + sortRatio
    Run 167.3410.716.29×
    Run 272.911.156.54×
    Run 367.9510.36.59×

    Spread over 3 runs: pandas mask + sort_values CV 4.4% / polars filter + sort CV 3.9% / ratio CV 2.5%

    The two calls

    df[df['v'] > 0.5].sort_values('v')
    df.filter(pl.col('v') > 0.5).sort('v')

    Conditions

    Half the rows survive the filter, then get sorted ascending.

    Where this number does not apply

    Sorting a column that is already sorted is much cheaper for both sides.

    Reproduce

    cd bench && python run.py --run 1 --out ../data/run1.json