[issue27078] Make f'' strings faster than .format: BUILD_STRING opcode?
Antti Haapala
report at bugs.python.org
Sat Aug 27 08:23:50 EDT 2016
Antti Haapala added the comment:
So does this (new opcode) count as a new feature? It would be great to give f'' strings a flying start, saying that not only they're cool, they're also faster than anything that you've used before.
Here some more mini-benchmarks with serhiy's patch2 applied, the times are pretty stable:
% python3.6 -mtimeit -s 'x = 42' '"%s-" % x'
10000000 loops, best of 3: 0.184 usec per loop
% python3.6 -mtimeit -s 'x = 42' 'f"{x}-"'
10000000 loops, best of 3: 0.142 usec per loop
and
% python3.6 -mtimeit -s 'x = "42"' 'f"{x}{x}"'
10000000 loops, best of 3: 0.0709 usec per loop
% python3.6 -mtimeit -s 'x = "42"' '"%s%s" % (x,x)'
1000000 loops, best of 3: 0.213 usec per loop
python3.6 -mtimeit -s 'x = "42"' '"".join((x, x))'
10000000 loops, best of 3: 0.155 usec per loop
This is only really achievable with some kind of bytecode support.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27078>
_______________________________________
More information about the Python-bugs-list
mailing list