Cut and dry… while I never have enough logical operations for it to be a performance bottleneck – I wonder, would I be better off using bitwise and (&) and bitwise or (|) as opposed to the same-named logical operators (&& and ||) if possible? Perhaps the question can be prefaced by the fact that I don’t know of a library to convert Java to assembly to see the # of operations.
Share
Bitwise operators avoid branching instructions, even in Java code execution. As a result you have no expensive branch prediction misses and no jumps at all.
From my experience, they can be measurably faster when used in code that is executed often enough. Keep in mind, though, that the bitwise operators are not short-circuiting ones, which may actually have a negative impact on performance in some cases.
That said, such micro-optimizations should only be used as a last resort and only after a profiler tells you to do so – readability and maintainability comes first.