Is making a temporary variable or incrementing faster?

29 views Asked by At

I have a code that goes like:

++state;
do_work();
--state;

do_work might modify and use state. I cannot simply replace state with state+1 in do_work.

Would using a temporary variable be faster than decrementing on a mainstream processor such as an Intel or ARM?

int tmp = state++;
do_work();
state = tmp;

Before you say that I am doing premature optimization, I will use the clearer first way over the last way regardless. I am just curious if that is actually slower than the other way.

0

There are 0 answers