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


Groups > comp.lang.python > #66595

Re: Does CPython already has Peephole optimizations?

From Peter Otten <__peter__@web.de>
Subject Re: Does CPython already has Peephole optimizations?
Date 2014-02-17 09:45 +0100
Organization None
References <CAFtnWG9Zm75mQY--54mYMyHvNhhanr51VBjRDMK4xMoo_AaxNQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7087.1392626746.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web