[issue27078] Make f'' strings faster than .format: BUILD_STRING opcode?

Demur Rumed report at bugs.python.org
Wed Jul 13 09:14:44 EDT 2016


Demur Rumed added the comment:

fstrtup2.patch is a bit more of an involved optimization for when we are joining 2 strings. Instead it emits BINARY_ADD. This may be considered too 'niche' since it only triggers when the substitution occurs at the start or end of a string & there is only one substitution

However, it reduces the "X is {x}" testcase on my machine to 4.9 usec

Interesting thing, to consider ceiling of what we can do,

Prefixing ./python -m timeit -s "x=1"
'%s'%x 1.08 usec
'%s'%(x,) 2.04 usec
str(x) 2.9 usec
f'{x}' 3.65 usec

So we should not be aiming to compete with %. It may be worthy to convert the code to generate "x is {}".format calls tho

----------
Added file: http://bugs.python.org/file43704/fstrtup2.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27078>
_______________________________________


More information about the Python-bugs-list mailing list