3 ms·
While the techniques described here are academically interesting, don't expect your code to run magically faster if you use them in practice. I once benchmarked
by frontfor 13y ago
While the techniques described here are academically interesting, don't expect your code to run magically faster if you use them in practice. I once benchmarked the performance of the "common version" of #9 implemented in C compared to swapping using a temporary variable like so:
int tmp = a;
a = b;
b = tmp;
It turned out that the bitwise swap was slower. In other words this sort of "clever" bit-level hack does not necessarily translate to higher performance.
And I would recommend the first chapter of "Matters Computational" written by Jörg Arndt, which includes many more advanced bitwise operations: http://www.jjj.de/fxt/#fxtbook http://www.jjj.de/fxt/#fxtbook. This book is more like a cookbook rather than an introductory book.
EDIT: debugged!