Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66595 > unrolled thread

Re: Does CPython already has Peephole optimizations?

Started byPeter Otten <__peter__@web.de>
First post2014-02-17 09:45 +0100
Last post2014-02-17 09:45 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Does CPython already has Peephole optimizations? Peter Otten <__peter__@web.de> - 2014-02-17 09:45 +0100

#66595 — Re: Does CPython already has Peephole optimizations?

FromPeter Otten <__peter__@web.de>
Date2014-02-17 09:45 +0100
SubjectRe: Does CPython already has Peephole optimizations?
Message-ID<mailman.7087.1392626746.18130.python-list@python.org>
Laxmikant Chitare wrote:

> Hello All,
> 
> I read about this article:
> 
http://www.python.org/workshops/1998-11/proceedings/papers/montanaro/montanaro.html
> 
> Just wanted to clarify whether CPython already includes these kind of byte
> code optimizations? Are all the temporary variables removed when byte code
> is generated?

You can find out for yourself:

Python 3.4.0rc1+ (default:2ba583191550+, Feb 12 2014, 00:08:44) 
[GCC 4.6.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> def f():
...     a, b, c = 1, 2, 3
... 
>>> dis.dis(f)
  2           0 LOAD_CONST               4 ((1, 2, 3))
              3 UNPACK_SEQUENCE          3
              6 STORE_FAST               0 (a)
              9 STORE_FAST               1 (b)
             12 STORE_FAST               2 (c)
             15 LOAD_CONST               0 (None)
             18 RETURN_VALUE
>>> def g():
...     q = 2 + 3j
... 
>>> dis.dis(g)
  2           0 LOAD_CONST               3 ((2+3j))
              3 STORE_FAST               0 (q)
              6 LOAD_CONST               0 (None)
              9 RETURN_VALUE

If you can read C there is also

http://hg.python.org/cpython/file/180e4b678003/Python/peephole.c

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web