[docs] [issue37512] Error in the documentation about string concatenation

Dmitriy report at bugs.python.org
Sat Jul 6 07:32:57 EDT 2019


Dmitriy <mironovd at icloud.com> added the comment:

Yes, optimization is really not working in case of prepending. In case of multiple references I couldn't get quadratic time grow.

Concerning the Windows, yes, the optimization may be not always efficient:

>>> timeit('a+="a"', setup='a=""', number=10000)
0.0011690999999984797
>>> timeit('a+="a"', setup='a=""', number=100000)
0.01114439999999206
>>> timeit('a+="a"', setup='a=""', number=1000000)
0.10783829999999739
>>> timeit('a+="a"', setup='a=""', number=10000000)
5.636337499999996

As I understand this is the case related to OS memory management.


But on Linux I got fairly predictable results:

>>> timeit('a+="a"', setup='a=""', number=10000)
0.0006532900151796639
>>> timeit('a+="a"', setup='a=""', number=100000)
0.006340583000564948
>>> timeit('a+="a"', setup='a=""', number=1000000)
0.06438201799755916
>>> timeit('a+="a"', setup='a=""', number=10000000)
0.6354853530065157
>>> timeit('a+="a"', setup='a=""', number=100000000)
6.365498173021479


Also I have found the mention about optimization in PEP8
https://www.python.org/dev/peps/pep-0008/#programming-recommendations

So maybe it would be nice to add some notes or reference to the part of upper PEP in docs about optimizations in CPython to make it more clear.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37512>
_______________________________________


More information about the docs mailing list