Fatest standard way to sum bytes (and their squares)?
a.schmolck at gmail.com
Mon Aug 13 19:49:19 CEST 2007
Alexander Schmolck <a.schmolck at gmail.com> writes:
> Erik Max Francis <max at alcyone.com> writes:
>> Alexander Schmolck wrote:
>>> Is this any faster?
>>> ordSum, orsSumSq = (lambda c:c.real,c.imag)(sum(complex(ord(x),ord(x)<<1)
>>> for x in data))
>> That's pretty clever, but I neglected to mention that I need to accumulate the
>> sums as ints/longs to avoid losing precision, so converting to floating point
>> isn't an optional.
> I think you can safely use this trick (provided it really makes things faster)
> provided you sum blocks no larger than 2**(53-8) bytes;
Forgot about the squares; make this 2**(53-16); still pretty big.
More information about the Python-list