2.3 list reverse() bug?

Alex Martelli aleaxit at yahoo.com
Sun Dec 28 09:53:17 CET 2003


On Saturday 27 December 2003 11:11 pm, Andrew MacIntyre wrote:
> On Fri, 26 Dec 2003, Alex Martelli wrote:
> > list(x) is my favourite way to make a shallow copy of list x, but x[:]
> > and copy.copy(x) are essentially equivalent.
>
> Behaviourally yes, performance wise no.

[alex at lancelot x]$ timeit.py -c -s 'x=range(999)' 'x[:]'
100000 loops, best of 3: 18.3 usec per loop

[alex at lancelot x]$ timeit.py -c -s 'x=range(999)' 'list(x)'
10000 loops, best of 3: 22 usec per loop

[alex at lancelot x]$ timeit.py -c -s 'x=range(999)' -s'import copy' 
'copy.copy(x)'
10000 loops, best of 3: 22 usec per loop

Close enough, for me, that the words "essentially equivalent" appear
to be quite justified.  How much of your program's time is spent doing
shallow copies of lists, that these tiny differences in overhead are, to
you, ESSENTIAL to your program's performance?


Alex






More information about the Python-list mailing list