dict の参照 is ~1.12× slower than __slots__ 属性
Attribute access on a `__slots__` class is ~12% faster than a dict key lookup.
Result
| Run | dict の参照 | __slots__ 属性 | Ratio |
|---|---|---|---|
| Run 1 | 27.522 | 24.713 | 1.11× |
| Run 2 | 26.647 | 23.944 | 1.11× |
| Run 3 | 27.037 | 24.073 | 1.12× |
Spread over 3 runs: dict の参照 CV 1.3% / __slots__ 属性 CV 1.4% / Ratio CV 0.4%
Conditions
500,000 simple lookups.
Where this number does not apply
A 12% gap is small enough that design reasons should win.
Reproduce
cd bench && python micro_py.py --out ../data/run.json --samples 21