Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18453
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <stefan-usenet@bytereef.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.095 |
| X-Spam-Evidence | '*H*': 0.81; '*S*': 0.00; 'indeed,': 0.07; 'magnitude': 0.09; 'magnitude.': 0.16; 'subject:vs.': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'faster,': 0.23; 'formatting': 0.23; 'numeric': 0.23; 'stefan': 0.24; 'bit': 0.28; 'seem': 0.30; "isn't": 0.33; 'header:User- Agent:1': 0.33; 'to:addr:python-list': 0.34; 'loop': 0.34; 'surprised': 0.34; 'skip:" 20': 0.35; 'charset:us-ascii': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'received:org': 0.38; "it's": 0.40; 'to:addr:python.org': 0.40; 'difference': 0.40; 'your': 0.61; 'order': 0.62; 'choice.': 0.64; 'real-world': 0.64; 'deal,': 0.67; 'difference.': 0.84; 'timings': 0.84 |
| Date | Tue, 3 Jan 2012 21:53:14 +0100 |
| From | Stefan Krah <stefan-usenet@bytereef.org> |
| To | python-list@python.org |
| Subject | Re: .format vs. % |
| References | <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <mailman.4321.1325544682.27778.python-list@python.org> <fd8933b8-0cca-4127-8f9b-38b056ee075a@h12g2000yqg.googlegroups.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <CALwzidnvLsamJ=TchqjhZCrXHnP0LyOvg+gSCo+zJ2Edy0W=7w@mail.gmail.com> <4F02DE94.8000506@gmail.com> <mailman.4345.1325591422.27778.python-list@python.org> <9mh490FbvuU2@mid.individual.net> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| In-Reply-To | <9mh490FbvuU2@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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4386.1325623995.27778.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1325623995 news.xs4all.nl 6878 [2001:888:2000:d::a6]:60011 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18453 |
Show key headers only | View raw
Neil Cerutti <neilc@norwich.edu> wrote:
> On 2012-01-03, Stefan Krah <stefan-usenet@bytereef.org> wrote:
> > $ ./python -m timeit -n 1000000 '"%s" % 7.928137192'
> > 1000000 loops, best of 3: 0.0164 usec per loop
>
> % 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
Indeed, I was a bit surprised by the magnitude of the difference.
Your timings seem to be in line with the difference seen in the
real-world benchmark. It isn't a big deal, considering that the
numeric formatting functions have to so many options, e.g:
>>> "{:020,}".format(712312312.2)
'00,000,712,312,312.2'
Still, it's nice to have a faster choice.
Stefan Krah
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
.format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:19 -0800
Re: .format vs. % Andrew Berg <bahamutzero8825@gmail.com> - 2011-12-31 12:34 -0600
Re: .format vs. % Yaşar Arabacı <yasar11732@gmail.com> - 2011-12-31 20:34 +0200
Re: .format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:44 -0800
Re: .format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:44 -0800
Re: .format vs. % Yaşar Arabacı <yasar11732@gmail.com> - 2011-12-31 20:51 +0200
Re: .format vs. % Evan Driscoll <edriscoll@wisc.edu> - 2011-12-31 13:47 -0500
Re: .format vs. % Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-01 13:11 -0800
Re: .format vs. % Terry Reedy <tjreedy@udel.edu> - 2012-01-02 05:29 -0500
Re: .format vs. % Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-01 13:11 -0800
Re: .format vs. % Alexander Kapps <alex.kapps@web.de> - 2011-12-31 19:59 +0100
Re: .format vs. % Tim Chase <python.list@tim.thechases.com> - 2011-12-31 13:24 -0600
Re: .format vs. % Lie Ryan <lie.1296@gmail.com> - 2012-01-01 06:34 +1100
Re: .format vs. % Robert Kern <robert.kern@gmail.com> - 2011-12-31 19:43 +0000
Re: .format vs. % Terry Reedy <tjreedy@udel.edu> - 2011-12-31 16:09 -0500
Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-02 14:00 -0800
Re: .format vs. % Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-02 17:59 -0800
Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 03:52 +0000
Re: .format vs. % Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-02 22:58 -0700
Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 06:15 +0000
Re: .format vs. % Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-03 01:16 -0700
Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 05:26 -0800
Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 11:38 -0800
Re: .format vs. % Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 15:02 -0500
Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 12:16 -0800
Re: .format vs. % Andrew Berg <bahamutzero8825@gmail.com> - 2012-01-03 04:55 -0600
Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 12:47 +0100
Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 13:58 +0000
Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 15:17 +0100
Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 15:15 +0000
Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 15:24 +0000
Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 19:46 +0000
Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 12:00 -0800
Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 21:53 +0100
Re: .format vs. % Chris Angelico <rosuav@gmail.com> - 2012-01-04 00:04 +1100
Re: .format vs. % Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-02 17:51 -0800
Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 03:47 +0000
Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-03 07:47 -0800
Re: .format vs. % alex23 <wuwei23@gmail.com> - 2012-01-03 18:26 -0800
Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-04 00:25 -0800
Re: .format vs. % alex23 <wuwei23@gmail.com> - 2012-01-04 16:23 -0800
Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-04 17:41 -0800
csiph-web