Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Pyhon 2.x or 3.x, which is faster? Date: Mon, 7 Mar 2016 22:39:49 -0500 Lines: 60 Message-ID: References: <87d1r6iltx.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 7p4PzjmIrusBYC2iUcxO+w/lMnmZJpRqWx/Lc1wXO6Zw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'ast': 0.09; 'dict': 0.09; 'globals': 0.09; 'lookup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:which': 0.09; 'python': 0.10; 'jan': 0.11; '2.7': 0.13; 'def': 0.13; '2.7:': 0.16; '2.7?': 0.16; '2016': 0.16; 'first:': 0.16; 'focus,': 0.16; 'helps.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'test()': 0.16; 'test():': 0.16; 'time.time()': 0.16; 'version?': 0.16; 'xrange': 0.16; 'wrote:': 0.16; 'detect': 0.18; 'integer': 0.18; '>>>': 0.20; 'versions': 0.20; 'changes': 0.20; 'work,': 0.21; '3.x': 0.22; 'next,': 0.22; 'pass': 0.22; 'appears': 0.23; 'bit': 0.23; 'replacing': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'installed': 0.26; 'header:X -Complaints-To:1': 0.26; 'compare': 0.27; 'least': 0.27; 'question': 0.27; 'function': 0.28; 'away.': 0.29; 'array': 0.29; 'actively': 0.30; 'operations': 0.31; 'seconds': 0.31; 'though,': 0.32; 'getting': 0.33; 'run': 0.33; 'tue,': 0.34; 'previous': 0.34; 'running': 0.34; 'text': 0.35; 'done': 0.35; 'improving': 0.35; 'replaced': 0.35; 'something': 0.35; 'level': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'doing': 0.38; 'version': 0.38; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'care': 0.60; 'your': 0.60; 'body': 0.61; 'default': 0.61; 'further': 0.62; 'received:96': 0.63; 'more': 0.63; 'here:': 0.63; 'latest': 0.64; 'within': 0.64; 'mar': 0.65; '2.7.': 0.84; '3.4': 0.84; '3.5.1': 0.84; '3.8': 0.84; '8.4': 0.84; 'cripple': 0.84; 'locals': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104319 On 3/7/2016 8:33 PM, BartC wrote: >> On Tue, Mar 8, 2016 at 12:00 PM, BartC wrote: >>> def whiletest(): >>> | i=0 >>> | while i<=100000000: >>> | | i+=1 >>> >>> whiletest() >>> >>> Python 2.7: 8.4 seconds >>> Python 3.1: 12.5 seconds >>> Python 3.4: 18.0 seconds >>> >>> Even if you don't care about speed, you must admit that there appears >>> to be >>> something peculiar going on here: why would 3.4 take more than twice >>> as long >>> as 2.7? What do they keep doing to 3.x to cripple it on each new >>> version? > Let me ask you a follow-on question first: how slow does a new Python > version have to be before even you would take notice? We now run a suite of benchmarks daily on latest versions of 2.7 and default (3.6) to compare not to each other but to previous days to detect changes within either branch. I verified your result with installed 64 bit 2.7.11 versus 3.5.1 import time def test(): i=0 while i<=100000000: i+=1 start = time.time() test() print(time.time() - start) 4.4 (2.7) versus 10.7 (3.5) Running loop at top level instead of inside the function doubled the time. Replacing globals dict lookup with function locals array lookup really helps. Next, I replaced the body of the function with for i in range(100000000): pass This time, 3.5 wins: 3.8 versus 2.7. Whoops, unfair. Change range to xrange in 2.7 and the time is 1.5. Neither version optimizes the do-nothing loop away. A further version of CPython might. There are people working on improving the speed of CPython. Integer operations are not their focus, though, because that can be done in numpy. Text operations have been getting work, and at least one person is actively working on an ast optimizer. -- Terry Jan Reedy