Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] Briefer string format

Alexander Belopolskyalexander.belopolsky at gmail.com
Tue Jul 21 06:02:28 CEST 2015


On Mon, Jul 20, 2015 at 11:35 PM, Tim Peters <tim.peters at gmail.com> wrote:> >>> dis(f)>   2           0 LOAD_CONST               3 ('2')>               3 RETURN_VALUE>> That is, the peephole optimizer got rid of "%d" % 2 entirely,> replacing it with the string constant "2".  So, in all, it's more> surprising that it takes so long to load a constant ;-)>Hmm.  I stand corrected:$ python3 -mtimeit -s "a=2" "'%s' % a"10000000 loops, best of 3: 0.124 usec per loop$ python3 -mtimeit -s "a=2" "'{}'.format(a)"1000000 loops, best of 3: 0.215 usec per loopit is 2x rather than 20x speed difference.-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150721/0f85478a/attachment.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp