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 <rep...@bugs.python.org> <http://bugs.python.org/issue23486> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com