[New-bugs-announce] [issue26574] replace_interleave can be optimized for single character byte strings

Josh Snider report at bugs.python.org
Wed Mar 16 19:28:10 EDT 2016


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 <report at bugs.python.org>
<http://bugs.python.org/issue26574>
_______________________________________


More information about the New-bugs-announce mailing list