'Does an integer smaller than 255 perform as fast as an unsigned character?

I know that an unsigned character's size is 8 bits, and the size of an integer is 32 bits.

But I want to know if I perform an operation between two integers below 255, is it safe to say it is as fast as performing the same operation on two unsigned characters of the same value of that integers?

Example:

int Int2 = 0x10;
int Int1 = 0xff;

unsigned char Char0 = 0x10;
unsigned char Char1 = 0xff;

Int1  + Int2 ; // Is calculating this
Char0 + Char1; // Faster than this??

Update: Let's put this in the context as someone suggested

for (unsigned char c=0;c!=256;c++){ // does this loop

   std::cout<<c; // dont mind this line it can be any statement
}

for (int i=0;i!=256;i++){ // perform faster than this one??

   std::cout<<i;// this too
}


Solution 1:[1]

I know that an unsigned character's size is 8 bits

This is not necessarily always the case in C++. But it may be true in particular implementation of C++.

and the size of an integer is 32 bits.

There are several integer types in C++. In fact, character types are integer types as well.

Int1  + Int2 ; // Is calculating this
Char0 + Char1; // Faster than this??

Integers of lower rank than int are promoted to int (or unsigned int in rare cases) when used as operand of most binary operators. Both operators in the example operate on int after the promotion. You don't use the result at all, so there's no need for the compiler to produce any code, so they should be equally fast in this trivial example.

Whether one piece of code is faster than the other depends on many factors. It's not possible to accurately guess which way it would go without context.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1