I am working on an application where I have to keep data sequenced, every unit of data comes with a sequence number where, I check if the sequence number is 1 greater than the previous one, if it is, I increase my received count by 1. My question is, Is there a difference between :
1. in increasing my received count by one.
AND
2. assigning the last received sequence number to received count.
Thanks.
It sounds like a classic premature optimization question to me. Generally increasing value would mean "fetch original->change->store", while assigning would be "fetch other->store new". The "other" would probably be fetched already, thus saving even more clock cycles. Thus assigning would probably be faster.
BUT increment by 1 is usually very well optimized by the compilers and CPU's so that it wouldn't require any fetching or storing. It can very well be done in one CPU command, thus eliminating any difference, and in fact making increment by 1 probably better option performance-wise.
Confused? Good.
Point is that this is the kind of optimization you should not be doing, unless you benchmarked a bottle neck. Then you benchmark the options and chose the best.
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