Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; '(b)': 0.07; 'variables': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Does': 0.09; 'python': 0.11; 'def': 0.12; 'article:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:already': 0.16; 'url:file': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; '(a)': 0.24; 'byte': 0.24; 'header:X-Complaints-To:1': 0.27; '(c)': 0.29; 'skip:( 20': 0.30; 'code': 0.31; 'linux': 0.33; 'url:python': 0.33; 'there': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'kind': 0.63; 'more': 0.64; 'temporary': 0.65; 'url:c': 0.67; '2014,': 0.84; 'subject:skip:o 10': 0.84; 'url:cpython': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Does CPython already has Peephole optimizations? Date: Mon, 17 Feb 2014 09:45:47 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdb5c1.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392626746 news.xs4all.nl 2915 [2001:888:2000:d::a6]:45480 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66595 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