I know- Premature optimization.
But I've got code that's supposed to find out if a position is changed vs a cached position.
Current code is:
if(abs(newpos-oldpos) > 1){
.....
}
Is it more efficient to use the following?
if(abs(newpos-oldpos) != 0){
....
}
Why or why not? I'm currently debating it my head which is more readable and was wondering if there was a performance difference I was missing.
Why not this?
if (newpos != oldpos) {
...
}
More efficient than both due to the lack of abs()
, and clearer to boot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With