
July 20, 2015
11:02 p.m.
On Mon, Jul 20, 2015 at 11:35 PM, Tim Peters <tim.peters@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 loop it is 2x rather than 20x speed difference.