looking before leaping - Python Dict: Unscientific benchmarks of lookup methods
Marius Kruger
amanic at gmail.com
Tue Jun 28 11:25:12 UTC 2011
I just read this and thought this may interest you.
A long time ago I suggested LBYL in a review and was told catching the
exception it better.
I'm not saying this benchmark is perfect but these days I'm a big
believer in "Measure don't guess."
http://www.bigjason.com/blog/python-dict-unscientific-benchmarks-lookup-methods/
==
Conclusion
Use the in operator whenever possible. The convenience ofdict.get is
worth the very small time difference in my mind, but the exception
method is unacceptably slow.
The good news is that the exception performance issues were obviously
addressed to some extent in python 3 and are now only twice as slow.
Maybe this is common knowledge already, but it took me by surprise. I
am interested to hear of other methods that are commonly used (if
any). Feel free to fork the gist and give it a spin.
==
I saw this in a buzz from Guillermo Gonzalez
(https://profiles.google.com/guillo.gonzo#buzz)
--
<>< Marius ><>
More information about the bazaar
mailing list