Simon Cross <hodgestar <at> gmail.com> writes: > My tests show that the old-style % formatting is much faster when the > final string is 20 characters or less: > > $ ./python -m timeit "'....|....|....|...%s' % '12'" > 10000000 loops, best of 3: 0.0764 usec per loop You are the victim of a constant-folding optimization: $ ./python -m timeit "'....|....|....|...%s' % '12'" 10000000 loops, best of 3: 0.0926 usec per loop $ ./python -m timeit -s "s='12'" "'....|....|....|...%s' % s" 1000000 loops, best of 3: 0.525 usec per loop >>> def f(): return '....|....|....|...%s' % '12' ... >>> dis.dis(f) 1 0 LOAD_CONST 3 ('....|....|....|...12') 3 RETURN_VALUE cheers Antoine.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4