Message236234
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_)
[...] |
|
Date |
User |
Action |
Args |
2015-02-19 21:59:13 | craigh | set | recipients:
+ craigh |
2015-02-19 21:59:13 | craigh | set | messageid: <1424383153.37.0.19682507186.issue23486@psf.upfronthosting.co.za> |
2015-02-19 21:59:13 | craigh | link | issue23486 messages |
2015-02-19 21:59:13 | craigh | create | |
|