This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xiang.zhang
Recipients serhiy.storchaka, vstinner, xiang.zhang
Date 2016-12-09.19:33:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481312008.07.0.341994225324.issue28921@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2016-12-09 19:33:28xiang.zhangsetrecipients: + xiang.zhang, vstinner, serhiy.storchaka
2016-12-09 19:33:28xiang.zhangsetmessageid: <1481312008.07.0.341994225324.issue28921@psf.upfronthosting.co.za>
2016-12-09 19:33:28xiang.zhanglinkissue28921 messages
2016-12-09 19:33:27xiang.zhangcreate