什么整数宽度在C中处理得更快?

S.J*_*.J. 5 c integer

在32位CPU上使用16位宽度或32位宽度整数时速度是否有差异?或者,64位拱上的32位与64位int?

换句话说,如果我有一些适合uint16_t范围的值,我应该使用"unsigned int"代替性能是否重要?

ice*_*ime 15

所述<stdint.h>头部提供的typedef其可以是你的情况很有帮助"至少具有某些特定宽度最快整数类型":

以下每种类型都指定一个整数类型,该类型通常在具有至少指定宽度的所有整数类型中运行最快.

typedef名称 int_fastN_t指定宽度至少为N uint_fastN_t 的最快有符号整数类型.typedef名称指定宽度至少为N 的最快无符号整数类型.

需要以下类型:

int_fast8_t               uint_fast8_t  
int_fast16_t              uint_fast16_t  
int_fast32_t              uint_fast32_t  
int_fast64_t              uint_fast64_t  
Run Code Online (Sandbox Code Playgroud)