Ulrich Eckhardt <ulrich.eckha...@dominolaser.com> writes: > So again, why is one faster than the other? What am I missing?
The .format() syntax is actually a function, and that alone carries some overload. Even optimizing the lookup may give a little advantage: >>> from timeit import Timer >>> setup = "a = 'spam'; b = 'ham'; c = 'eggs'" >>> t1 = Timer("'%s, %s and %s for breakfast' % (a, b, c)", setup) >>> t2 = Timer("'{}, {} and {} for breakfast'.format(a, b, c)", setup) >>> print(min(t1.repeat())) >>> print(min(t2.repeat())) >>> setup = "a = 'spam'; b = 'ham'; c = 'eggs'; f = '{}, {} and {} for >>> breakfast'.format" >>> t3 = Timer("f(a, b, c)", setup) >>> print(min(t3.repeat())) 0.3076407820044551 0.44008257299719844 0.418146252995939 But building the call frame still takes its bit of time. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list