GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • [ date ]
  • [ thread ]
  • [ subject ]
  • [ author ]

This view

  • Original page
  • New address

GeezerVison is showing mail.python.org — [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

  • Previous message: [Python-Dev] optimization required: .format() is much slower than %
  • Next message: [Python-Dev] [Python-3000] Stabilizing the C API of 2.6 and 3.0
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

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.

  • Previous message: [Python-Dev] optimization required: .format() is much slower than %
  • Next message: [Python-Dev] [Python-3000] Stabilizing the C API of 2.6 and 3.0
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

More information about the Python-Dev mailing list
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.