Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: Pyhon 2.x or 3.x, which is faster? Date: Sat, 12 Mar 2016 10:51:29 +0000 Lines: 62 Message-ID: References: <56df6761$0$1588$c3e8da3$5496439d@news.astraweb.com> <56e2579e$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de hBqaQz5Q7NdT0e4+WjtE8gCcWw2jwFgl6UFgzRfbWONA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(even': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'strings.': 0.07; 'highlight': 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; 'worked,': 0.09; 'bug': 0.10; 'python': 0.10; 'def': 0.13; 'ignore': 0.14; '2016': 0.16; 'measures': 0.16; 'optimised': 0.16; 'pypy.': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'test()': 0.16; 'test():': 0.16; 'workaround?': 0.16; 'written.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'refers': 0.18; 'programmer': 0.18; 'runs': 0.18; 'language': 0.19; '>>>': 0.20; 'issue.': 0.20; 'fix': 0.21; 'lawrence': 0.22; 'minor': 0.22; 'trying': 0.22; 'demonstrate': 0.23; 'references': 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'chris': 0.26; 'fri,': 0.27; 'correct': 0.28; 'this.': 0.28; 'if,': 0.29; 'strings,': 0.29; 'character': 0.29; 'print': 0.30; 'code': 0.30; "can't": 0.32; 'language.': 0.32; 'problem': 0.33; 'michael': 0.33; 'usually': 0.33; 'steven': 0.33; 'but': 0.36; 'there': 0.36; 'possible': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'difference': 0.38; "won't": 0.38; 'version': 0.38; 'wrong': 0.38; 'why': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'different': 0.63; 'our': 0.64; 'mar': 0.65; 'here': 0.66; 'special': 0.73; 'benchmark': 0.84; 'optimisation': 0.84; 'pythonistas,': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.129.0 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:104689 On 12/03/2016 10:31, BartC wrote: > On 12/03/2016 10:06, alister wrote: >> On Fri, 11 Mar 2016 22:24:45 +0000, BartC wrote: >> >>> On 11/03/2016 21:59, Mark Lawrence wrote: >>>> On 11/03/2016 18:57, BartC wrote: >>> >>>> def test(): >>>> s="" >>>> for i in range(10000000): >>>> s+="*" >>>> print (len(s)) >>>> >>>> test() >>> >>>> The minor snag that you might like to correct with your microbenchmark, >>>> which any experienced Python programmer knows, is that you *NEVER, >>>> EVER* >>>> create strings like this. >>> >>> Why not? Chris said his version runs much faster (even allowing for >>> different machines), and might have a special optimisation for it. >>> >>> And I think it can be optimised if, for example, there are no other >>> references to the string that s refers to. >>> >>> So what's wrong with trying to fix it rather that using a workaround? >> >> because the "workarround" is not a workarround it is the correct way to >> do it >> the code above is a workarround for somone who does not know the pythonic >> method to do this >> >> S= "*"*10000000 > > This is a benchmark that measures the cost of adding to a string a > character at a time. > > In practice the final length of the string is not known, and the > characters added at each stage are not known. > > Although the strings won't usually be that big; the benchmark > exaggerates here to highlight a possible issue with += on strings. And > it worked, as there can be big difference with or without the += > optimisation in place. > > It also showed a possible bug or problem with PyPy. > > You can't demonstrate all this by just writing s="*"*10000000. > There is no possible issue with += on strings, there is a known issue. What to do about has all ready been discussed by myself, Dennis Lee Bieber, Michael Torrie and Steven D'Aprano, but you've chosen to ignore what we've written. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence