Dmitriy <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue37512>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com