[Mono-dev] What's the most efficient way to do XOR two byte arrays?

Chris Eelmaa chriseelmaa at gmail.com
Wed Nov 19 13:17:19 UTC 2014


There is virtually no difference between Array.Copy and
Buffer.BlockCopy when dealing with large buffers.

If you are rapidly calling Array.Copy with smaller buffers, then yes,
you can save some milliseconds if you switch to Buffer.BlockCopy,
because it skips checks / makes less function calls, and there's less
overhead. As I said, the difference comes to play when we are dealing
with very small data rapidly.


That said,

you can make some serious gains when you're dealing with large
buffers. You just need to parallelize it, and make sure there is no
false cache sharing.

The other trick is to see what Mono.Simd offers. I don't see a reason
why Xoring 128-bit blocks at once shouldn't be possible. You want
something similiar:
http://stackoverflow.com/questions/15067119/how-can-i-use-simd-to-accelerate-xor-two-blocks-of-memory

Note I have absolutely no experience with Mono.Simd but I imagine it's
pretty cool.


More information about the Mono-devel-list mailing list