Changes by Ethan Furman et...@stoneleaf.us:
--
nosy: +ethan.furman
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23486
___
___
Python-bugs-list
New submission from Craig Holmquist:
Running the attached test script:
$ time python test.py enum
real0m6.546s
user0m6.530s
sys 0m0.007s
$ time python test.py int
real0m0.384s
user0m0.377s
sys 0m0.000s
I encountered this with a script that yielded a sequence of
Ethan Furman added the comment:
Craig Holmquist wrote:
-
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.
So for every object you compare against every Enum
Craig Holmquist added the comment:
I may not have been clear before. What I mean is, code like this:
for obj in get_objects():
if obj.category == Cat.cat1:
#do something
elif obj.category == Cat.cat2:
#do something else
elif obj.category == Cat.cat3 or obj.category
Craig Holmquist added the comment:
It seems like performance is drastically improved by doing this:
class Category(Enum):
tiny = 1
medium = 2
large = 3
tiny = Category.tiny
medium = Category.medium
In other words, resolving Category.tiny and Category.medium is what's slow.
The