This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author craigh
Recipients craigh
Date 2015-02-19.21:59:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424383153.37.0.19682507186.issue23486@psf.upfronthosting.co.za>
In-reply-to
Content
Running the attached test script:

$ time python test.py enum

real	0m6.546s
user	0m6.530s
sys	0m0.007s
$ time python test.py int

real	0m0.384s
user	0m0.377s
sys	0m0.000s

I encountered this with a script that yielded a sequence of objects (potentially a few hundred thousand of them) and categorized them with instances of an Enum subclass.  The consumer of that iteration processes each object with a switch-case-like comparison of the category, checking it sequentially against each instance of the Enum.  This seems like a fairly common use case.

From cProfile it looks like EnumMeta.__getattr__ and _is_dunder are the main bottlenecks:

[...]
      7/1    0.000    0.000    0.000    0.000 abc.py:194(__subclasscheck__)
        1    0.000    0.000    0.001    0.001 enum.py:1(<module>)
        3    0.000    0.000    0.000    0.000 enum.py:132(<genexpr>)
  2000021    0.988    0.000    0.988    0.000 enum.py:16(_is_dunder)
       19    0.000    0.000    0.000    0.000 enum.py:24(_is_sunder)
  2000002    1.825    0.000    2.813    0.000 enum.py:241(__getattr__)
       17    0.000    0.000    0.000    0.000 enum.py:282(__setattr__)
        3    0.000    0.000    0.000    0.000 enum.py:342(_get_mixins_)
        3    0.000    0.000    0.000    0.000 enum.py:387(_find_new_)
[...]
History
Date User Action Args
2015-02-19 21:59:13craighsetrecipients: + craigh
2015-02-19 21:59:13craighsetmessageid: <1424383153.37.0.19682507186.issue23486@psf.upfronthosting.co.za>
2015-02-19 21:59:13craighlinkissue23486 messages
2015-02-19 21:59:13craighcreate