Are variables of the same type with bigger values slower?

If I create variable with the int32_t type with the value of 1 for example and another variable with the same type but the value will be the int32 max value, will computations be faster in expressions with the first variable rather than the second?

>Solution :

In the comments, you asked

So, theoretically the bigger value variable could be faster than the smaller one depending on computations?

which generalizes the question to

  • Could computation time differ between inputs with value 1 and inputs with value MAX_INT?

For many elementary operations such as addition and bit-wise OR, the answer is No.

For arbitrary computation, the answer is Most definitely yes, unless you are very careful to prevent it.

The possibility of correlation between input values and time is quite significant in the information security community. Good search terms: "timing side channel" and "constant-time implementation".

A related concern is whether the power consumption of the arithmetic circuitry correlates to input values, even when the time is constant.

Leave a Reply