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
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/V3TP2QFDIDYYITQWRV37XMA3JEUGHSM5/
Code of Conduct: http://python.org/psf/codeofconduct/