A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2008-May/079938.html below:

[Python-Dev] optimization required: .format() is much slower than %

[Python-Dev] optimization required: .format() is much slower than %Eric Smith eric+python-dev at trueblade.com
Sat May 31 03:48:30 CEST 2008
Eric Smith wrote:
> Eric Smith wrote:
>> Nick Coghlan wrote:
>>> Secondly, the string % operator appears to have an explicit 
>>> optimisation for the 'just return str(self)' case. This optimisation 
>>> is missing from the new string format method.
>>
>> I'll see if I can optimize this case.
> 
> 3.0, from svn:
> $ ./python.exe -m timeit "'some text with {0}'.format('nothing')"
> 100000 loops, best of 3: 3.14 usec per loop
> 
> 3.0, with PyUnicode_ExactCheck, skipping __format__ lookup:
> $ ./python.exe -m timeit "'some text with {0}'.format('nothing')"
> 100000 loops, best of 3: 2.32 usec per loop
> 
> I could probably improve this some more, by skipping the creation of the 
> object used to describe the format_spec.
> 
> Compare with:
> $ ./python.exe -m timeit "'some text with %s' % 'nothing'"
> 1000000 loops, best of 3: 1.37 usec per loop

r63826 has an optimization when formatting types that are exactly 
unicode, long, or float (not subclasses).  Unfortunately it's only for 
3.0.  For 2.6 it's messier.  I'm still pondering what to do with that. 
I'll get to it sometime, but maybe after the beta.

There's much more that can be done, but I'd like to profile it before I 
just start guessing.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4