Deepcopying a byte string is quicker than copying it - problem?
Frank Millman
frank at chagford.com
Thu Feb 27 01:30:09 EST 2014
Hi all
I noticed this a little while ago, but dismissed it as a curiosity. On
reflection, I decided to mention it here in case it indicates a problem.
This is with python 3.3.2.
C:\>python -m timeit -s "import copy" "copy.copy('a'*1000)"
100000 loops, best of 3: 6.91 usec per loop
C:\>python -m timeit -s "import copy" "copy.deepcopy('a'*1000)"
100000 loops, best of 3: 11.8 usec per loop
C:\>python -m timeit -s "import copy" "copy.copy(b'a'*1000)"
10000 loops, best of 3: 79.9 usec per loop
C:\>python -m timeit -s "import copy" "copy.deepcopy(b'a'*1000)"
100000 loops, best of 3: 11.7 usec per loop
As you can see, deepcopying a string is slightly slower than copying it.
However, deepcopying a byte string is orders of magnitude quicker than
copying it.
Actually, looking closer, it is the 'copy' that is slow, not the 'deepcopy'
that is quick..
Expected, or odd?
Frank Millman
More information about the Python-list
mailing list