[New-bugs-announce] [issue24700] array compare is hideously slow
swanson
report at bugs.python.org
Fri Jul 24 01:01:14 CEST 2015
New submission from swanson:
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
----------
components: Library (Lib)
messages: 247234
nosy: swanson
priority: normal
severity: normal
status: open
title: array compare is hideously slow
type: performance
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24700>
_______________________________________
More information about the New-bugs-announce
mailing list