pandas Series.rolling(50).mean() is ~2.74× slower than polars rolling_mean(50) for a 50-row rolling mean
Same window, same column, same row order.
Result
| Run | pandas Series.rolling(50).mean() | polars rolling_mean(50) | Ratio |
|---|---|---|---|
| Run 1 | 12.98 | 4.59 | 2.83× |
| Run 2 | 12.36 | 4.56 | 2.71× |
| Run 3 | 16.32 | 5.96 | 2.74× |
Spread over 3 runs: pandas Series.rolling(50).mean() CV 15.3% / polars rolling_mean(50) CV 15.8% / ratio CV 2.3%
The two calls
df['v'].rolling(50).mean() df['v'].rolling_mean(window_size=50) Conditions
400,000 float values in the order they were generated.
Where this number does not apply
Rolling windows over grouped keys behave differently and are not measured here.
Reproduce
cd bench && python run.py --run 1 --out ../data/run1.json