Mailing List Archive

[issue5109] array.array constructor very slow when passed an array object.
New submission from Malcolm Purvis <malcolm@purvis.id.au>:

Copying an array.array object via the array constructor is some 100x
slower than using slicing or even converting the array to a string and
then passing that string to the array constructor.

Running the attached program on a 2.2GHz MacBook Pro (OSX 10.5.5, 4GB
RAM) produces this output:

$ python2.6 array_test.py
Constructor: 18.5617749691
Slice: 0.169251918793
String: 0.375015974045

>From a look at arraymodule.c it seems that array_new() does not have a
special case for the array type and therefore uses the generic sequence
copy code rather than using memcpy(), like it can for slicing.

----------
components: Library (Lib)
files: array_test.py
messages: 80815
nosy: malcolmp
severity: normal
status: open
title: array.array constructor very slow when passed an array object.
type: performance
versions: Python 2.6
Added file: http://bugs.python.org/file12893/array_test.py

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5109>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5109] array.array constructor very slow when passed an array object. [ In reply to ]
David W. Lambert <lambertdw@corning.com> added the comment:

memcpy won't work if the data type changes. (possibly signed <->
unsigned same-byte-count works).

----------
nosy: +LambertDW

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5109>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5109] array.array constructor very slow when passed an array object. [ In reply to ]
Malcolm Purvis <malcolm@purvis.id.au> added the comment:

It's true that memcpy won't work when the data type changes, but I would
assume (with no evidence to back me up) that the most common case for
passing an array into the array's constructor would be when data types
are the same. That case would be case to detect especially and use
memcpy for.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5109>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com