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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to