Use a short and cast, or use an int and don’t?

Hi, i have variable which i know will always be defined as within the range that a short has, but the compiler wants a (short) cast, this is taking place in a large nested loop so i’m trying to save as much computing time as possible.

My question is: would it be faster to just use an int and don’t cast or to use a short and cast, the difference in my code would be:

int startH = (x - radius < 0) ? 0 : x - radius; 


short startH = (short)((x - radius < 0) ? 0 : x - radius); 

I only wonder because an int takes up 4 bytes which i thought might take more time to write to than a 2 byte short.

submitted by /u/djdylex
[link] [comments]

Leave a Reply