Christian Heimes added the comment:

bytes(x ^ y for x, y in zip(a, b)) is super-slow if you have to do XOR inside a 
hot loop for a couple of ten thousand times. int.from_bytes + int.to_bytes is 
about ten times faster. I expect bitwise ops of bytes to be even faster and 
more readable.

$ python3.3 -m timeit -n 100000 -s "a = b'a'*64; b = b'b'*64" "bytes(x ^ y for 
x, y in zip(a, b))"
100000 loops, best of 3: 7.5 usec per loop

$ python3.3 -m timeit -n 100000 -s "a = b'a'*64; b = b'b'*64" "i = 
int.from_bytes(a, 'little') ^ int.from_bytes(b, 'little'); i.to_bytes(64, 
'little')"
100000 loops, best of 3: 0.866 usec per loop

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19251>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to