This is very very strange, but generally speaking, itβs better to just change the value.
In any case, checking and setting the value has approximately the same overhead, so why do you need to do both in some cases?
Now, if you are interested in whether to overwrite some kind of user-defined type (say, a list of 100,000 words) or if you need to check whether you need to overwrite it first (say, just by checking a boolean value or timestamp), then you should first check because the cost of checking a boolean or timestamp is much less than storing a large number of words in memory.
This, of course, depends on various things, such as, regardless of whether the memory is stored in your memory, how expensive the βcheckβ is, how often you need to rewrite the value compared to how often it does not need to be overwritten, and, Of course, the size of the memory.
source share