4 ms·
Also dot means attribute means less speed.
by lesingerouge 9y ago
Also dot means attribute means less speed.
- dom0 9y agoIf you have to worry about that, you've taken many wrong turns in the past.
- deathanatos 9y agoThat's a huge micro-optimization. For a trivial example of a class having the attributes "a", "b" and "c", and a dict of the same, In [4]: %timeit d['b'] # dict 10000000 loops, best of 3: 42.7 ns per loop In [6]: %timeit f.b # class using __slots__ The slowest run took 30.10 times longer than the fastest. This could mean that an intermediate result is being cached. 10000000 loops, best of 3: 44 ns per loop In [9]: %timeit b.b # class using __dict__ 10000000 loops, best of 3: 48.1 ns per loop You're talking <6ns per access; except in the very exceptional case where you know you need this, in Python of all languages, it's an over optimization. The maintainability of having the stupid-simple class vastly outweighs the speed.
- deleted 9y ago[deleted]