[Python-ideas] Briefer string format

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jul 21 05:28:44 CEST 2015


On Mon, Jul 20, 2015 at 11:16 PM, Steve Dower <Steve.Dower at microsoft.com>
wrote:

> Making f"" strings subtly faster isn't going to solve your performance
> issue, and while I'm not advocating wastefulness, this looks like a
> premature optimization, especially when put alongside the guaranteed heap
> allocations and very likely IO that are also going to occur.


One thing I know for a fact is that the use of % formatting instead of
.format makes a significant difference in my applications.  This is not
surprising given these timings:

$ python3 -mtimeit "'%d' % 2"
100000000 loops, best of 3: 0.00966 usec per loop
$ python3 -mtimeit "'{}'.format(2)"
1000000 loops, best of 3: 0.216 usec per loop

As a result, my rule of thumb is to avoid the use of .format in anything
remotely performance critical.

If f"" syntax is implemented as a sugar for .format - it will be equally
useless for most of my needs.  However,
I think it can be implemented in a way that will make me consider switching
away from % formatting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150720/363948fc/attachment.html>


More information about the Python-ideas mailing list