Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed6.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.060 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'deprecated': 0.09; 'necessary,': 0.09; 'did,': 0.16; 'runtime.': 0.16; 'subject:vs.': 0.16; 'wrote:': 0.18; 'this?': 0.19; 'header:In-Reply-To:1': 0.22; 'formatting': 0.23; 'replacing': 0.23; 'stefan': 0.24; 'adds': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.34; 'all.': 0.34; '...': 0.36; 'charset:us-ascii': 0.37; 'skip:" 10': 0.37; 'think': 0.37; 'received:org': 0.38; 'should': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'skip:o 30': 0.63; 'real-world': 0.64; 'profile': 0.73; 'benchmark': 0.84 Date: Tue, 3 Jan 2012 15:17:15 +0100 From: Stefan Krah To: python-list@python.org 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> <9mgfrtFt0U5@mid.individual.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9mgfrtFt0U5@mid.individual.net> User-Agent: Mutt/1.5.18 (2008-05-17) 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325600237 news.xs4all.nl 6893 [2001:888:2000:d::a6]:43125 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18409 Neil Cerutti wrote: > > In the real-world telco benchmark for _decimal, replacing the > > single line > > > > outfil.write("%s\n" % t) > > > > with > > > > outfil.write("{}\n".format(t)) > > > > adds 23% to the runtime. I think %-style formatting should not > > be deprecated at all. > > When it becomes necessary, it's possible to optimize it by > hoisting out the name lookups. > ... > outfil_write = outfil.write > append_newline = "{}\n".format > ... > outfil_write(append_newline(t)) > ... Did you profile this? I did, and it still adds 22% to the runtime. Stefan Krah