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.

classification
Title: Performance boost for array repeat
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, klaas
Priority: normal Keywords: patch

Created on 2006-11-29 05:49 by klaas, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
array_repeat.diff klaas, 2006-11-29 05:49 performance boost for array.repeat
Messages (4)
msg51414 - (view) Author: Mike Klaas (klaas) Date: 2006-11-29 05:49
Copy in exponentially-increasing sized chunks when performing array repeat.  This enables fast initialization of large arrays.  Performance is about an order of magnitude increase for single-element arrays, and about two orders of magnitude faster for single-element character arrays (see comments)
msg51415 - (view) Author: Mike Klaas (klaas) Date: 2006-11-29 05:54
Benchmarks on slightly-contended machine; before & after

[ python-trunk]$ python -m timeit -s "from array import array" "array('c', '\0')*100000"
100 loops, best of 3: 4 msec per loop
[ python-trunk]$ ./python -m timeit -s "from array import array" "array('c', '\0')*100000"
100000 loops, best of 3: 14.5 usec per loop

[ python-trunk]$ python -m timeit -s "from array import array" "array('i', [0])*100000"
100 loops, best of 3: 3.42 msec per loop
[ python-trunk]$ ./python -m timeit -s "from array import array" "array('i', [0])*100000" 
1000 loops, best of 3: 517 usec per loop

[ python-trunk]$ python -m timeit -s "from array import array" "array('i', [0,1,2,3])*100000"
100 loops, best of 3: 4.95 msec per loop
[ python-trunk]$ ./python -m timeit -s "from array import array" "array('i', [0,1,2,3])*100000"
100 loops, best of 3: 2.55 msec per loop

[ python-trunk]$ python -m timeit -s "from array import array" "array('c', '\0'*100)*1000"
10000 loops, best of 3: 46.6 usec per loop
[ python-trunk]$ ./python -m timeit -s "from array import array" "array('c', '\0'*100)*1000"
100000 loops, best of 3: 19.6 usec per loop

[ python-trunk]$ python -m timeit -s "from array import array" "array('c', '\0'*1000)*100"
10000 loops, best of 3: 22.8 usec per loop
[ python-trunk]$ ./python -m timeit -s "from array import array" "array('c', '\0'*1000)*100"
10000 loops, best of 3: 20.7 usec per loop
msg51416 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-11-29 09:31
How does this patch relate to patch #1569291?
msg51417 - (view) Author: Mike Klaas (klaas) Date: 2006-11-29 18:25
The patches have virtually identical functionality and performance characteristics.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44288
2006-11-29 05:49:19klaascreate