c++ - Does it make sense to verify if values are different in a setter -


i remember saw somewhere (probably in github) example in setter:

void myclass::setvalue(int newvalue) {     if (value != newvalue) {         value = newvalue;     } } 

for me doesn't make lot of sense, wonder if gives performance improvement.

the deeper instruction pipeline (and gets deeper , deeper on intel platform @ least), higher cost of branch misprediction.

when branch mispredicts, instructions mispredicted path still move through pipeline. work performed on these instructions wasted since not have been executed had branch been correctly predicted

so yes, adding if int code can hurt performance. write l1 cached, possibly long time. if write has visible operation have interlocked start with.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -