So suppose I have a number called num
, if some condition A happens, then increase the number by 1, else decrease it.
I could write the code like this:
if (A) ++num;
else --num;
This piece of code could also be written without any if-else, but would involve more arithmetics (just simple basic arithmetics, no exponents, logarithms or anything that one would need a scientific calculator to do!) Something like this:
num = num * x + y;
The question is, would the first or the second block of code perform faster? (This is in Java, btw).
(Please don't say it wouldn't make any difference. This is just very 'rudimentary' version of what I'm trying to do. But suppose there were an extremely good profiler that could measure the difference in runtime between these two's, which one would be faster?)
Thanks