dict.fromkeys is ~1.49× slower than set() で重複除去
`dict.fromkeys` dedupes ~1.5× faster than `set()` — and keeps insertion order.
Result
| Run | set() で重複除去 | dict.fromkeys | Ratio |
|---|---|---|---|
| Run 1 | 5.326 | 8.003 | 0.67× |
| Run 2 | 5.440 | 8.207 | 0.66× |
| Run 3 | 5.757 | 8.086 | 0.71× |
Spread over 3 runs: set() で重複除去 CV 3.3% / dict.fromkeys CV 1.0% / Ratio CV 3.4%
Conditions
Deduping 300,000 items with 5,000 distinct values.
Where this number does not apply
If order does not matter the gap matters less; both require hashable items.
Reproduce
cd bench && python micro_py.py --out ../data/run.json --samples 21