Re: percent faster than format()?

2013-04-23 Thread Lele Gaifax
Ulrich Eckhardt 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

Re: percent faster than format()?

2013-04-23 Thread Ulrich Eckhardt
Am 23.04.2013 10:26, schrieb Chris “Kwpolska” Warrick: On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt wrote: Am 23.04.2013 06:00, schrieb Steven D'Aprano: If it comes down to micro-optimizations to shave a few microseconds off, consider using string % formatting rather than the format metho

Re: percent faster than format()? (was: Re: optomizations)

2013-04-23 Thread Chris Angelico
On Wed, Apr 24, 2013 at 12:36 AM, Steven D'Aprano wrote: > # Using Python 3.3. > > py> from timeit import Timer > py> setup = "a = 'spam'; b = 'ham'; c = 'eggs'" > py> t1 = Timer("'%s, %s and %s for breakfast' % (a, b, c)", setup) > py> t2 = Timer("'{}, {} and {} for breakfast'.format(a, b, c)", s

Re: percent faster than format()? (was: Re: optomizations)

2013-04-23 Thread Steven D'Aprano
On Tue, 23 Apr 2013 09:46:53 +0200, Ulrich Eckhardt wrote: > Am 23.04.2013 06:00, schrieb Steven D'Aprano: >> If it comes down to micro-optimizations to shave a few microseconds >> off, consider using string % formatting rather than the format method. > > Why? I don't see any obvious difference b

Re: percent faster than format()? (was: Re: optomizations)

2013-04-23 Thread Chris “Kwpolska” Warrick
On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt wrote: > Am 23.04.2013 06:00, schrieb Steven D'Aprano: >> >> If it comes down to micro-optimizations to shave a few microseconds off, >> consider using string % formatting rather than the format method. > > > Why? I don't see any obvious difference

percent faster than format()? (was: Re: optomizations)

2013-04-23 Thread Ulrich Eckhardt
Am 23.04.2013 06:00, schrieb Steven D'Aprano: If it comes down to micro-optimizations to shave a few microseconds off, consider using string % formatting rather than the format method. Why? I don't see any obvious difference between the two... Greetings! Uli -- http://mail.python.org/mailma