[Python-ideas] Briefer string format

Steve Dower Steve.Dower at microsoft.com
Tue Jul 21 05:39:33 CEST 2015

That's almost certainly something that can be improved though, and maybe it's worth some investment from you. Remember, Python doesn't get better by magic - it gets better because someone gets annoyed enough about it that they volunteer to fix it (at least, that's how I ended up getting so involved :) ).

My wild guess is that calling int.__format__ is the slow part, though I'd have hoped that it wouldn't be any slower for default formatting... guess not. We've got sprints coming up at PyData next week, so maybe I'll try and encourage someone to take a look and see what can be improved here.


Top-posted from my Windows Phone
From: Alexander Belopolsky<mailto:alexander.belopolsky at gmail.com>
Sent: ‎7/‎20/‎2015 20:28
To: Steve Dower<mailto:Steve.Dower at microsoft.com>
Cc: Eric V. Smith<mailto:eric at trueblade.com>; python-ideas<mailto:python-ideas at python.org>
Subject: Re: [Python-ideas] Briefer string format

On Mon, Jul 20, 2015 at 11:16 PM, Steve Dower <Steve.Dower at microsoft.com<mailto: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/20150721/5b79b8e5/attachment.html>

More information about the Python-ideas mailing list