Q:

Is there any difference Shallow copy and deep copy in Run time and Performance?

l = [[2,3,4],[5,6,7]]

d = deepcopy(l)
s = copy(l)

p[0][0] = 1
s[0][0] = 1

print(l)

Here, the outputs are same,but my question is there is any difference between Shallow copy and deep copy in Run time and Performance ?

A:

%timeit on my laptop gives 13.4us for deepcopy vs. 594 ns for copy, so it takes about 23x longer.
This seems reasonable. The copy only has to copy one 2-element list; the deepcopy has to copy one 2-element list and two 3-element lists, and it's also got some extra overhead from the recursion. If the lists were a lot longer, but the nesting not a lot deeper, I'd expect the difference to get smaller, but still, it will always be substantial.
Laurent LAPORTE's [list(i) for i in l] takes 2.01us on my laptop—only 3x as slow as a copy instead of 23x. Of course it only has a fixed depth (2, in the specific case of his answer) rather than unlimited, but in this case, we've got a fixed-depth list, and that's not too unusual.
But performance will rarely be a good reason to choose one over the other. That assignment to the shallow copy's s[0][0] = 1 is going to change the original list's l[0][0] to 1 as well. If you want that, use copy (or, more simply in this case, just list). If you don't, use deepcopy. And if you want exactly a specific depth, use a specific depth. (Getting the answer you need is always better than getting the wrong answer fast.)

