I was talking with my colleague and he said that in code it’s better to multiply than divide, but he didn’t argue why it is better, so I decided to find out, so:
For example, which case is better:
var caseOne = x / 2;
or
var caseTwo = x * 0.5;
And how do each do performance-wise?
Thanks for all answers 🙂
These kind of micro-optimizations are really not worth the readability cost. You should really write code that makes sense. Oftentimes the compiler makes optimizations anyway.
Write code that will be easy to read, maintain, and explain in the future, so that you don’t have to work around your solution, or worse, introduce bugs.