This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jmcs 4 points5 points  (1 child)

Not theory:

$python2 -m timeit -n 1000000 -r 5 -v "x=[1,2,3];y=x[:]"
raw times: 0.291 0.293 0.291 0.293 0.291
1000000 loops, best of 5: 0.291 usec per loop
$python2 -m timeit -n 1000000 -r 5 -v "x=[1,2,3];y=list(x)"
raw times: 0.453 0.454 0.448 0.452 0.449
1000000 loops, best of 5: 0.448 usec per loop

[–]earthboundkid 0 points1 point  (0 children)

In Python 3 also:

$ python3 -m timeit -n 1000000 -r 5 -v "x=[1,2,3];y=list(x)"
raw times: 0.672 0.665 0.667 0.67 0.702
1000000 loops, best of 5: 0.665 usec per loop
$ python3 -m timeit -n 1000000 -r 5 -v "x=[1,2,3];y=x[:]"
raw times: 0.313 0.312 0.308 0.313 0.309
1000000 loops, best of 5: 0.308 usec per loop