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

Chris “Kwpolska” Warrick kwpolska at gmail.com
Tue Apr 23 04:26:38 EDT 2013


On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt
<ulrich.eckhardt at 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



More information about the Python-list mailing list