x86_64 架构下int long加法运算性能对比

编写int_long_performance.c代码如下

#include 
#include 
#include 

void main(){
	time_t c_start, c_end;
	unsigned int i=0;
	unsigned long l=0;

	printf("int size=%d\n", sizeof(i));
	c_start = clock();
	for(;i<0xFFFFFFFF;i++);
	c_end = clock();

	printf("int performance %f\n", difftime(c_end, c_start));

	printf("long size=%d\n", sizeof(l));
	c_start = clock();
	for(;l<0xFFFFFFFF;l++);
	c_end = clock();
	printf("long performance %f\n", difftime(c_end, c_start));
}

编译指令(关闭优化)

gcc -O0 int_long_performance.c

执行结果

[yeqiang@localhost tmp]$ ./a.out 
int size=4
int performance 34489020.000000
long size=8
long performance 33828099.000000

总结
可以看到,x86_64架构下4字节无符号整形和8字节无符号整形加法性能没有明显差距

你可能感兴趣的:(c)