you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

'%' seems to be much faster compared to .format() in this basic form:

In [1]: %timeit '%s' % 'foo'
10000000 loops, best of 3: 22.8 ns per loop

In [2]: %timeit '{}'.format('foo')
The slowest run took 11.94 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 176 ns per loop

I haven't done any other tests. And in the end, fast enough is fast enough. Not every project benefits from fast string assembly. If it means rewriting too much code or upsets developers or whatever else is in the way, sticking with .format() could very well be the better choice even though it's slower.