Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.118 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.02; 'subject:Python': 0.06; 'subject:Does': 0.09; 'python': 0.11; 'sorts': 0.16; '>>>': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'operators': 0.31; 'sep': 0.31; '(2)': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'received:10': 0.37; 'to:addr:python- list': 0.38; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'easy': 0.60; 'more': 0.64; 'power': 0.76; 'answered,': 0.84; 'yourself..': 0.84; '2013,': 0.91 From: Nick Cash To: "python-list@python.org" Subject: RE: Does Python optimize low-power functions? Thread-Topic: Does Python optimize low-power functions? Thread-Index: AQHO8q/TPhorZ1x6VkqNa0rb0I9iu5pHjJlA Date: Fri, 6 Dec 2013 19:32:00 +0000 References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> In-Reply-To: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [70.166.238.194] x-forefront-prvs: 0052308DC6 x-forefront-antispam-report: SFV:NSPM; SFS:(189002)(199002)(51694002)(46102001)(80022001)(66066001)(74706001)(83072001)(65816001)(74876001)(74316001)(74366001)(4396001)(49866001)(47736001)(79102001)(59766001)(77982001)(50986001)(47976001)(63696002)(54356001)(53806001)(51856001)(54316002)(56776001)(76482001)(85306002)(81686001)(47446002)(74502001)(31966008)(74662001)(81816001)(81342001)(56816005)(85852002)(80976001)(69226001)(90146001)(81542001)(2656002)(76786001)(33646001)(76796001)(87266001)(87936001)(76576001)(83322001)(19580395003)(24736002); DIR:OUT; SFP:; SCL:1; SRVR:DM2PR06MB543; H:DM2PR06MB542.namprd06.prod.outlook.com; CLIP:70.166.238.194; FPR:; RD:InfoNoRecords; MX:1; A:1; LANG:en; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: npcinternational.com 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386358331 news.xs4all.nl 2878 [2001:888:2000:d::a6]:38358 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61179 >My question is, what do Python interpreters do with power operators where = the power is a small constant, like 2? Do they know to take the shortcut? Nope: Python 3.3.0 (default, Sep 25 2013, 19:28:08)=20 [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dis >>> dis.dis(lambda x: x*x) 1 0 LOAD_FAST 0 (x)=20 3 LOAD_FAST 0 (x)=20 6 BINARY_MULTIPLY =20 7 RETURN_VALUE =20 >>> dis.dis(lambda x: x**2) 1 0 LOAD_FAST 0 (x)=20 3 LOAD_CONST 1 (2)=20 6 BINARY_POWER =20 7 RETURN_VALUE =20 The reasons why have already been answered, I just wanted to point out that= Python makes it extremely easy to check these sorts of things for yourself= .