Issue1499095
Created on 2006-06-01 20:03 by collinwinter, last changed 2006-06-03 08:22 by rhettinger.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
optimise_in_const_ops.patch
|
collinwinter,
2006-06-01 20:03
|
Optimise "in" ops on constant tuples, against r46597 |
|
|
|
msg50407 - (view) |
Author: Collin Winter (collinwinter) |
Date: 2006-06-01 20:03 |
|
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
|
|
msg50408 - (view) |
Author: Raymond Hettinger (rhettinger) |
Date: 2006-06-03 08:22 |
|
Logged In: YES
user_id=80475
Sorry, this enticing idea has already been explored and
rejected. This is issue is that the transformation is not
semanatically neutral. Currently, writing "{} in (1,2,3)"
returns False, but after the transformation would raise an
exception, "TypeError: dict objects are unhashable".
|
|
| Date |
User |
Action |
Args |
| 2006-06-01 20:03:07 | collinwinter | create | |
|