Newbie confused by 2 dimensional list

Peter Schneider-Kamp nowonder at nowonder.de
Tue Aug 8 07:14:02 EDT 2000


Duncan Booth wrote:
> 
> I'm not entirely convinced that increasing the amount of punctuation is
> really a sign of decreasing the level of desparation, but I will concede

I am generally a bit allergic to importing too many modules.

> that (somewhat to my surprise) the lambda and slice copy is faster than the
> copy function. You have to use numbers larger than 2 for this to become
> obvious: [["*"]*1000]*10000 is suitably large.

Actually I think the reason is pretty simple. I may be wrong, though.

copy.copy dispatches the copy operation to copy._copy_list.
That is one dictionary look up and an additional function
call overhead for each copy operation, because internally
copy._copy_list(x) calls x[:] to make the actual copy.

A short profiling shows that just eliminating the function
call (using a modified copy.py) and thereby cutting from
20002 calls to 10002 calls only leaves a marginal overhead.
(3 vs. 2 seconds --> 2.1 vs 2 seconds).

Peter
--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de




More information about the Python-list mailing list