int 比 long 快吗? [英] Is int faster than long?
问题描述
值 a
和 b
具有相同的输出:
int a = 0xEFEFEFEF;长 b = 0xEFEFEFEF;cout<<<<结束<<<<结束;
我听说 long
类型有更多的处理时间来计算,因为 long
应该转换为 int
进行计算.int
真的比 long
快吗?
这个问题从某种意义上说,long
是否比 int
更快,这个问题不可能得到普遍回答.>
代码可以在具有 32 位 long
和 16 位 int
的 16 位平台上运行,int
将在该平台上运行可能会更快 - 但不一定.另一方面,在具有 32 位int
和 64 位 long
的本机 32 位平台上,long
可能更快- 但不一定.
所以它依赖于平台,也依赖于编译器.最重要的是,通常对目标 CPU 的本机字长类型的操作并不比可能需要强制转换的操作慢(通常快)宽度为原生尺寸.
Values a
and b
have same output:
int a = 0xEFEFEFEF;
long b = 0xEFEFEFEF;
cout << a << endl << b << endl;
I heard that a long
type has more processing time to calculation because long
should be cast to int
for calculation. Is int
really faster then long
?
This question is impossible to answer universally in a sense whether long
is faster than int
.
The code could be ran on a 16-bit platform with 32-bit long
and 16-bit int
on which the int
would probably be faster - but not necessarily. On the other hand, on a native 32-bit platform which has 32-bitint
and 64-bit long
, the long
could be faster - but not necessarily.
So it is platform dependent, and compiler dependent. The bottom line is that usually the operations on target CPU's native word length types are no slower(usually faster) than the operations which may require casting the width to native size.
这篇关于int 比 long 快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!