[New-bugs-announce] [issue47005] Improve performance of bytes_repeat

Pieter Eendebak report at bugs.python.org
Sun Mar 13 15:01:26 EDT 2022

New submission from Pieter Eendebak <pieter.eendebak at gmail.com>:

The bytearray_repeat and bytearray_irepeat are inefficient for small arrays and a high number of repeats.
This can be improved by using the same approach is in the corresponding bytes_repeat method.


python -m pyperf timeit "b=bytearray([1,2,])*100" 

Mean +- std dev: [base100] 479 ns +- 29 ns -> [patch100] 274 ns +- 18 ns: 1.75x faster

python -m pyperf timeit "b=bytearray([1,2,])*1000"

Mean +- std dev: [base1000] 2.58 us +- 0.18 us -> [patch1000] 399 ns +- 26 ns: 6.46x faster

components: Interpreter Core
messages: 415077
nosy: pieter.eendebak
priority: normal
severity: normal
status: open
title: Improve performance of bytes_repeat
type: performance
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list