Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'over,': 0.05; 'python': 0.08; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'readable': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'exception': 0.12; 'magnitude.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:vs.': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'faster,': 0.23; 'formatting': 0.23; 'literal': 0.23; 'string': 0.24; 'cc:2**0': 0.24; 'stefan': 0.24; 'thanks.': 0.26; 'compile': 0.29; 'cc:addr:python.org': 0.29; 'andrew': 0.32; 'pretty': 0.32; "isn't": 0.33; 'header:User-Agent:1': 0.33; 'done': 0.34; 'loop': 0.34; 'skip:" 10': 0.37; 'but': 0.37; 'easier': 0.38; '(with': 0.39; "it's": 0.40; 'more': 0.61; 'order': 0.62; 'love': 0.62; 'received:websitewelcome.com': 0.64; 'received:184': 0.67; 'interest.': 0.68; 'received:69.56': 0.73 Date: Tue, 03 Jan 2012 12:00:23 -0800 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Neil Cerutti Subject: Re: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mh490FbvuU2@mid.individual.net> In-Reply-To: <9mh490FbvuU2@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2218 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 3 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325623876 news.xs4all.nl 6909 [2001:888:2000:d::a6]:58131 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18452 Neil Cerutti wrote: > On 2012-01-03, Stefan Krah wrote: >> Andrew Berg wrote: >>> To add my opinion on it, I find format() much more readable and easier >>> to understand (with the exception of the {} {} {} {} syntax), and would >>> love to see %-style formatting phased out. >> For me the %-style is much more readable. Also, it is significantly >> faster: >> >> $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' >> 1000000 loops, best of 3: 0.0164 usec per loop > > I have done a little more investigating, and the above is > arguably not fair. Python is interpolating that string at compile > time, as far as I can tell. Pretty cool, and not possible with > .format, but it's just regurgitating a string literal over and > over, which isn't of much interest. > > % is faster, but not by an order of magnitude. > > On my machine: > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" > 1000000 loops, best of 3: 0.965 usec per loop > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" > 1000000 loops, best of 3: 1.17 usec per loop > Good information. Thanks. ~Ethan~