[Python-Dev] optimization required: .format() is much slower than % (original) (raw)
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 PyUnicodeExactCheck, 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 formatspec. 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 ]