[issue23486] Enum member lookup is 20x slower than normal class attribute lookup

Ethan Furman report at bugs.python.org
Fri Feb 20 00:41:15 CET 2015


Ethan Furman added the comment:

Yup, you have it figured out.  It's the lookup that is the slowdown.

When performance is an issue one of the standard tricks is to create a local name, like you did with "tiny = Category.tiny".

For the curious (taken from the docstring for Enum.__getattr__):

    We use __getattr__ instead of descriptors or inserting into the enum
    class' __dict__ in order to support `name` and `value` being both
    properties for enum members (which live in the class' __dict__) and
    enum members themselves.

It is possible to store all the enum members /except/ for 'name' and 'value' in the class' __dict__, but I'm not sure it's worth the extra complication.

----------
title: Enum comparisons are 20x slower than comparing equivalent ints -> Enum member lookup is 20x slower than normal class attribute lookup

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


More information about the Python-bugs-list mailing list