Is using bitwise operations really faster than normal math on modern processors?

I saw several sources (some here and in the Wikipedia article on bitwise operation) say that using bitrate to calculate is faster than normal multiplication / division / addition. However, they also mentioned that this really only applies to older processors, and that most modern processors have made it so that the speeds are almost equal.

How valid is this operator? Is it safe to use regular math operands in Java or C #? Does bitverting use as a replacement for those operands that are really needed?

+3
source share
2 answers

You just leave it to the compiler. Good compilers are aware of the hardware they are targeting. If the compiler knows that bitwise operations are faster, then it can emit code to do it this way. You should always write code readable by a person in the clearest way that correctly expresses the operation being performed. Let the compiler do the rest.

As to whether it is true that bitwise operations can be faster than arithmetic, I believe that they are. Of course, many modern C ++ compilers will generate code that uses bitwise operations for arithmetic.

+9
source

, ( ... ).

, , , , , -, (, ).

JVM, , , , ( ).

, , - ... . , , , , , .

, - , , IMHO, . , .

: , , , , , .

+2

All Articles