[Patches] [ python-Patches-1499095 ] Optimise "in" operations on tuples of consts
SourceForge.net
noreply at sourceforge.net
Fri Jun 2 08:00:49 CEST 2006
Patches item #1499095, was opened at 2006-06-01 20:03
Message generated for change (Settings changed) made by gbrandl
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1499095&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Collin Winter (collinwinter)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Optimise "in" operations on tuples of consts
Initial Comment:
The following patch adds a peephole optimisation to the
compiler that optimises expressions like
x in (5, 6, 7)
to
x in frozenset([5, 6, 7])
That is, any "in" operation on tuples of constants will
be optimised to "in" operations on frozensets. Note
that the patch does not handle lists, as "in [constant
list]" is already optimised to "in (constant tuple)".
Additional tests for Lib/test/test_peepholer.py are
included. This patch is against r46597.
Some benchmarks (all times in usecs per loop):
./python -mtimeit '5 in (5, 6, 7, 8, 9)'
Unoptimised: 0.376
Optimised: 0.437
./python -mtimeit '9 in (5, 6, 7, 8, 9)'
Unoptimised: 1.14
Optimised: 0.436
./python -mtimeit '89 in (5, 6, 7, 8, 9)'
Unoptimised: 1.32
Optimised: 0.498
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1499095&group_id=5470
More information about the Patches
mailing list