java - Checking statement or assignation variable for performance? -
what instruction takes more time between if()
or variable initialization ?
will more efficient first check whether given variable has non-zero value , set if nonzero?
for example : boolean !
if (boolean) boolean = false;
or directly : boolean = false;
most faster not check. depend on type of object being set (in case, boolean, "simple set"). particularly special objects have "simple compare" , "complex set" benefit checking first.
and if easy check , hard change, "set" function should check itself.
an exception shared memory between processors there lot of contention, since writing memory force caches of other processors flushed, takes time.