Deepcopying a byte string is quicker than copying it - problem?
Frank Millman
frank at chagford.com
Thu Feb 27 04:02:26 EST 2014
"Frank Millman" <frank at chagford.com> wrote in message
news:lemm11$18r$1 at ger.gmane.org...
> 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
>
Thanks, Ian and Peter, for confirming that this is not expected.
I have created an issue on the bug tracker -
http://bugs.python.org/issue20791
Frank
More information about the Python-list
mailing list