[Patches] [ python-Patches-560736 ] Optimize list iteration
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 31 May 2002 14:07:08 -0700
Patches item #560736, was opened at 2002-05-26 10:25
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=560736&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: Optimize list iteration
Initial Comment:
Filled listobject's tp_iter slot with it's own iterator.
Speeds looping 5 to 10% (YMMV).
Only half of the speed-up comes from using tp_iter.
The rest came from code tweaking:
-- eliminate the it variable
-- invert the limit test to avoid jumps
-- bypass the GET_ITEM macro to allow index++ to be
combined with the lookup.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-31 16:07
Message:
Logged In: YES
user_id=80475
Replaced both instances with PyList_Check().
No other changes.
Re-verified compile, timings, and regression tests.
Okay to commit?
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-05-31 13:07
Message:
Logged In: YES
user_id=6380
Very close. It looks like you are using PySequence_Check()
where you should be using PyList_Check() though, since
listiter_next() really needs it to be a list! (Two place
have this mistake.)
Apart from that, it's good! (Note that the speedup
percentage is better when you use -O. :-)
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=560736&group_id=5470