Xiang Zhang added the comment: > I understand that count() is only used when the old and new patterns of > str.replace() have a different length.
Yes. I thought it won't help much since str.replace get many operations. But for long string, looks good: ./python3 -m perf timeit --compare-to ~/cpython/python -s 's="abcdefghihijklmnopqrstuvwxyz~!@##$%^&*()-=_+{}|"*100' 's.replace("a", "bc")' python: ..................... 7.36 us +- 0.04 us python3: ..................... 4.91 us +- 0.04 us Median +- std dev: [python] 7.36 us +- 0.04 us -> [python3] 4.91 us +- 0.04 us: 1.50x faster # 50% ??!! how? And this patch also applies to bytes since they share codes. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28921> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com