Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44167

Re: percent faster than format()? (was: Re: optomizations)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kwpolska@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.039
X-Spam-Evidence '*H*': 0.94; '*S*': 0.02; 'method.': 0.07; 'string': 0.09; 'formatting': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "%s'": 0.16; "'%s": 0.16; '(1,': 0.16; '10000000': 0.16; '23,': 0.16; 'eckhardt': 0.16; 'gpg': 0.16; 'subject:format': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'steven': 0.31; 'url:python': 0.33; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'rather': 0.38; 'url:mail': 0.40; 'from:charset:utf-8': 0.61; 'between': 0.67; 'obvious': 0.74; 'greetings!': 0.84; 'off,': 0.84; 'subject:skip:o 10': 0.84; 'why?': 0.91; 'url:tk': 0.95; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=IQ/jFew4+QAw0jmLLOdCGCH/1LWcn9RYVspAkPV1/yo=; b=u2d0xI0SPG/VVVCQRhK820W/KdcAVdA6RppeY2pJdWXzaYhJXgoIuMdwzBnBBcR/0/ LxY41hNId8u9V5J8cyvVdcI2sfacqgO4H8iDmudEucWVExnmMkZh06ye+QwLYCBVCOEU kkkLqW2gieHGztxF/wgGUy0txNUfdotqbJg5NQH2dABxOo35ZxqWtD6Ph/5RsYrvlGln NS8JoFmdjTk9ICjhozkP3cGPDBy3AQd8RX7pTgPZ5gLIOLNKEWX34e8T6Beqjyunsff3 x35uEpjKuda2eEYN1wPzOUntYxvj1gLw89Efa2Zio2XybEk4yjNnqpcy/NWZcm6G7azo rl5w==
X-Received by 10.50.57.166 with SMTP id j6mr17705383igq.21.1366705620123; Tue, 23 Apr 2013 01:27:00 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <dsqh4a-66p.ln1@satorlaser.homedns.org>
References <mailman.944.1366680414.3114.python-list@python.org> <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> <dsqh4a-66p.ln1@satorlaser.homedns.org>
From Chris “Kwpolska” Warrick <kwpolska@gmail.com>
Date Tue, 23 Apr 2013 10:26:38 +0200
Subject Re: percent faster than format()? (was: Re: optomizations)
To Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.964.1366705622.3114.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366705622 news.xs4all.nl 2198 [2001:888:2000:d::a6]:43819
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44167

Show key headers only | View raw


On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt
<ulrich.eckhardt@dominolaser.com> wrote:
> Am 23.04.2013 06:00, schrieb Steven D'Aprano:
>>
>> If it comes down to micro-optimizations to shave a few microseconds off,
>> consider using string % formatting rather than the format method.
>
>
> Why? I don't see any obvious difference between the two...
>
>
> Greetings!
>
> Uli
>
> --
> http://mail.python.org/mailman/listinfo/python-list

$ python -m timeit "a = '{0} {1} {2}'.format(1, 2, 42)"
1000000 loops, best of 3: 0.824 usec per loop
$ python -m timeit "a = '%s %s %s' % (1, 2, 42)"
10000000 loops, best of 3: 0.0286 usec per loop

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

optomizations Rodrick Brown <rodrick.brown@gmail.com> - 2013-04-22 21:19 -0400
  Re: optomizations Roy Smith <roy@panix.com> - 2013-04-22 21:53 -0400
    Re: optomizations Dan Stromberg <drsalists@gmail.com> - 2013-04-22 20:15 -0700
    Re: optomizations Rodrick Brown <rodrick.brown@gmail.com> - 2013-04-23 00:20 -0400
      Re: optomizations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 04:38 +0000
    Re: optomizations Chris Angelico <rosuav@gmail.com> - 2013-04-23 12:03 +1000
  Re: optomizations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 04:00 +0000
    Re: optomizations Chris Angelico <rosuav@gmail.com> - 2013-04-23 14:08 +1000
    percent faster than format()? (was: Re: optomizations) Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-04-23 09:46 +0200
      Re: percent faster than format()? (was: Re: optomizations) Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-23 10:26 +0200
        Re: percent faster than format()? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-04-23 16:57 +0200
          Re: percent faster than format()? Lele Gaifax <lele@metapensiero.it> - 2013-04-23 17:44 +0200
      Re: percent faster than format()? (was: Re: optomizations) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 14:36 +0000
        Re: percent faster than format()? (was: Re: optomizations) Chris Angelico <rosuav@gmail.com> - 2013-04-24 00:52 +1000

csiph-web