[issue13177] Avoid chained exceptions in lru_cache

Ezio Melotti report at bugs.python.org
Sat Oct 15 00:55:20 CEST 2011


Ezio Melotti <ezio.melotti at gmail.com> added the comment:

Canceling the chained exception might work as a workaround, but it requires yet another try/except and it's not very elegant in my opinion.

Raymond, about __missing__ it shouldn't be a problem here, because we are using "in" to look in the cache, and the cache is either a dict or an OrderedDict and they don't use __missing__.

I also did some crude benchmark using strings (see attached file):
always hit
try: 0.3375518321990967
in : 0.43109583854675293
always miss
try: 2.7987680435180664
in : 0.3211240768432617
5 hit, 5 miss
try: 18.37925887107849
in : 5.305108070373535
9 hit, 1 miss
try: 8.38001799583435
in : 6.524656057357788

Of course this will change if the hash() function gets more expensive, or if the ratio hits:miss is different.

----------
Added file: http://bugs.python.org/file23412/issue13177-bench.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13177>
_______________________________________


More information about the Python-bugs-list mailing list