1 Dec
2019
1 Dec
'19
12:39 a.m.
On Sat, Nov 30, 2019 at 01:30:55PM -0500, Ricky Teachey wrote:
Consulting two dictionaries instead of one is a very very very minor penalty.
It's more than twice as expensive: not only do you have to do two look ups rather than one, but you have to also look up the second dict as well. And there's the overhead of the ChainMap itself. $ ./python -m timeit -s "d = {}" "d.get('aardvark')" 500000 loops, best of 5: 702 nsec per loop $ ./python -m timeit -s "from collections import ChainMap" -s "d = ChainMap([{}, {}])" "d.get('aardvark')" 20000 loops, best of 5: 12.3 usec per loop That's 17 times slower on my PC. -- Steven