Antti Haapala added the comment:
Yet the test cases just prove what is so expensive there: name lookups (global
name `str`; looking up `join` on a string instance); building a tuple (for
function arguments) is expensive as well. Of course `__format__` will be costly
as well as it is not a slot-method, needs to build a new string etc.
However for strings, 'foo'.format() already returns the instance itself, so if
you were formatting other strings into strings there are cheap shortcuts
available to even overtake
a = 'Hello'
b = 'World'
'%s %s' % (a, b)
for fast string templates, namely, make FORMAT_VALUE without args return the
original if `PyUnicode_CheckExact` and no arguments, don't need to build a
tuple to join it.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue27078>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com