Message200401
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 |
|
Date |
User |
Action |
Args |
2013-10-19 10:56:52 | christian.heimes | set | recipients:
+ christian.heimes, georg.brandl, terry.reedy, pitrou, Ramchandra Apte, serhiy.storchaka |
2013-10-19 10:56:52 | christian.heimes | set | messageid: <1382180212.29.0.284873113196.issue19251@psf.upfronthosting.co.za> |
2013-10-19 10:56:52 | christian.heimes | link | issue19251 messages |
2013-10-19 10:56:52 | christian.heimes | create | |
|