DEV Community

Discussion on: How do you handle the disposable IF statements ?

Collapse
 
powerc9000 profile image
Clay Murray

I wouldn't worry too much about it. If this isn't run in any sort of loop the performance hit will be almost negligible.
We're talking on the order of a few hundred to a thousand CPU cycles in the worst case.
Which if it only run when the app loads or when the page opens will be, even on the slowest machine, a nanosecond blip.
Like if your wasting your time finding 0.00001 of a second to optimize you're looking in the wrong places.
The only case where you should care is if this were in a tight loop that was running millions of times.

Collapse
 
mazentouati profile image
Mazen Touati

Yeah, that's logical. Though, I'm not wasting such time on the nano optimization. At most, I use early exits and keep the rare scenario to the end. I think my discomfort is mental as I'm always anxious about such rarely used code without really doing anything about it.

Collapse
 
powerc9000 profile image
Clay Murray

That's fair.