Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'cpython': 0.05; 'great.': 0.07; 'subject:PEP': 0.07; 'variables': 0.07; 'implements': 0.09; '2.7': 0.14; '1.05': 0.16; '10000000': 0.16; 'cases)': 0.16; 'comma': 0.16; 'literals': 0.16; 'operator.': 0.16; 'received:65.55.116.7': 0.16; 'str.format()': 0.16; 'wed,': 0.18; 'to:name:python-list@python.org': 0.22; 'features,': 0.24; 'received:65.55.116': 0.24; 'skip:% 10': 0.24; 'header:In-Reply- To:1': 0.27; 'skip:- 40': 0.29; 'patch': 0.29; 'getting': 0.31; 'skip:c 30': 0.32; 'raw': 0.33; 'date:': 0.34; 'problem.': 0.35; 'test': 0.35; 'but': 0.35; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'new': 0.61; 'matter': 0.61; 'different': 0.65; 'optimized': 0.68; 'default': 0.69; '50%': 0.78; 'gain': 0.79; 'discovered': 0.83; '2.7.': 0.84; 'treats': 0.84; '2013': 0.98 X-TMN: [nWtJfd/+nBQEy3KQsQytpd7A4Qm7ZdI/] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: PEP 378: Format Specifier for Thousands Separator Date: Wed, 22 May 2013 14:52:15 +0300 Importance: Normal In-Reply-To: <519CAB19.7080203@nedbatchelder.com> References: , , , , , <519BD0D2.5080203@gmail.com>, , <519c30b0$0$6599$c3e8da3$5496439d@news.astraweb.com>, , <519c36c6$0$6599$c3e8da3$5496439d@news.astraweb.com> , <519CAB19.7080203@nedbatchelder.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 22 May 2013 11:52:15.0380 (UTC) FILETIME=[CDB03D40:01CE56E2] 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369223544 news.xs4all.nl 15905 [2001:888:2000:d::a6]:51929 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45725 ----------------------------------------=0A= > Date: Wed=2C 22 May 2013 07:25:13 -0400=0A= > From: ned@nedbatchelder.com=0A= [...]=0A= > You have to keep in mind that 2.7 is not getting any new features=2C no= =0A= > matter how small they seem. If you create a patch that implements the=0A= > comma flag in %-formatting=2C it *might* go into 3.x=2C but it will not g= o=0A= > into 2.7.=0A= >=0A= > --Ned.=0A= =0A= No problem. I have just discovered i was measuring the wrong thing.=0A= =0A= My test case is been optimized at compile time by CPython that treats "'%d'= % 12345" as a constant.=0A= My use case is different because I almost have no literals been used with %= operator.=0A= =0A= So my gain isn't that great. In fact it's faster with str.format() than %= =2C and it's even faster if I use the default format specifier.=0A= =0A= C:\Python27>python -m timeit -cv -n10000000 -s"v=3D12345" "'%d'%v"=0A= raw times: 10.5 10.7 10.7=0A= 10000000 loops=2C best of 3: 1.05 usec per loop=0A= =0A= C:\Python27>python -m timeit -cv -n10000000 -s"v=3D12345" "'{:d}'.format(v)= "=0A= raw times: 8.11 8.09 8.02=0A= 10000000 loops=2C best of 3: 0.802 usec per loop=0A= =0A= C:\Users\Josue\Documents\Python>python -m timeit -cv -n10000000 -s"v=3D1234= 5" "'{}'.format(v)"=0A= raw times: 5.3 5.5 5.62=0A= 10000000 loops=2C best of 3: 0.53 usec per loop=0A= =0A= Using variables (100% of cases) makes str.format() 50% faster than %. = =