computing with characters

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 12 02:39:47 EDT 2008


En Tue, 06 May 2008 08:16:55 -0300, <cokofreedom at gmail.com> escribió:

> I tend to do ", ".join("%s" % e for e in item)
>
> Is there any difference between this and str()?

Use the timeit module to measure performance:

C:\TEMP>python -m timeit "for i in xrange(10000): str(i)"
10 loops, best of 3: 81.8 msec per loop

C:\TEMP>python -m timeit "for i in xrange(10000): '%s' % i"
10 loops, best of 3: 78.5 msec per loop

The %s version consistently wins in my system -2.5.1 on WinXP- for a wide range of inputs.

-- 
Gabriel Genellina




More information about the Python-list mailing list