New submission from Josh Snider: replace_interleave in Objects/bytesobject.c and Objects/bytearrayobject.c can be optimized for the special case where the interleaving byte string is a single character.
Here's some quick results from timeit showing that it's about three times faster for the special case. * Before (cold start): >>> timeit.timeit('(b"x" * 2000000).replace(b"", b".")', number=1000) 7.619218342995737 * After (cold start): >>> timeit.timeit('(b"x" * 2000000).replace(b"", b".")', number=1000) 2.7605581780080684 For the non-special case, running timeit.timeit('(b"x" * 2000000).replace(b"", b".0")', number=10000) takes ~173 seconds on both versions. ---------- components: Library (Lib) files: bytes.patch keywords: patch messages: 261870 nosy: Josh Snider priority: normal severity: normal status: open title: replace_interleave can be optimized for single character byte strings type: performance versions: Python 3.6 Added file: http://bugs.python.org/file42179/bytes.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26574> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com