
Dec. 1, 2019
12:40 a.m.
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.
Well that's the death rattle on that particular crackpot idea.