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.

Author swanson
Recipients swanson
Date 2015-07-23.23:01:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1437692474.17.0.61027224315.issue24700@psf.upfronthosting.co.za>
In-reply-to
Content
Comparing two array.array objects is much slower than it ought to be.

The whole point of array.array is to be efficient:
 "array — Efficient arrays of numeric values"

But comparing them is orders of magnitude less efficient than comparing tuples or lists of numbers.  It would seem that array's __eq__ is converting every single number into an int, float, etc. first instead of just comparing the arrays in their native format.
If arrays can be copied efficiently, and bytearray can be copied or compared efficiently, there's no good reason for array's equality test to be so stupid.

example code:
-------------

from timeit import timeit

setup = '''
from array import array
a = array("I", %s)
ac = a.__copy__
b = ac()
t = tuple(a)
u = t[:1] + t[1:]
'''
for init in ("[1]*10", "[0xffffffff]*10", "[1]*1000", "[0xffffffff]*1000"):
 print("\n", init)
 for action in ("ac()", "a == b", "a == ac()", "t == u"):
  print(("%6.2f" % timeit(action, setup % init)), action)


results:
--------

 [1]*10
  0.31 ac()
  0.50 a == b
  0.73 a == ac()
  0.17 t == u

 [0xffffffff]*10
  0.29 ac()
  1.59 a == b
  1.87 a == ac()
  0.15 t == u

 [1]*1000
  0.84 ac()
 37.06 a == b
 37.72 a == ac()
  2.91 t == u

 [0xffffffff]*1000
  0.84 ac()
146.03 a == b
145.97 a == ac()
  2.90 t == u
History
Date User Action Args
2015-07-23 23:01:14swansonsetrecipients: + swanson
2015-07-23 23:01:14swansonsetmessageid: <1437692474.17.0.61027224315.issue24700@psf.upfronthosting.co.za>
2015-07-23 23:01:14swansonlinkissue24700 messages
2015-07-23 23:01:13swansoncreate