Significant performance difference between int and int8 or uint8 for midi values?


#1

Just wondering if changing all the ints representing midi values throughout my code to uint8 would make any real difference? Is it considered best practice?


#2

It will make no measurable difference to the performance of your code.

In terms of best practice, I believe the general advice is to prefer signed integers. However, if you’re doing arithmetic which might overflow, this is only well-defined for unsigned ints. Overflowing a signed int is undefined behaviour.

So, my advice would be: use signed ints, and ensure your values never overflow.