cpu时钟预取实例代码分享
#define MAX_LEN 1000000
static inline void prefetchnta(void *addr) //预取部分{ __asm__("movl %0, %%eax"::"a"(addr)); __asm__(".byte 0x0f, 0x18, 0x00");}
inline unsigned long long GetCPUTickCount(){ unsigned long high32 = 0; unsigned long low32 = 0;
__asm__("RDTSC" : "=a"(low32), "=d"(high32));
unsigned long long counter = high32; counter = (counter<<32) + low32;
return counter;}
int main(int argc, char* argv[]){ long long start, end; long long array[MAX_LEN]; int i;
for(i = 0; i < MAX_LEN; i++) //让cache失效 array[i]++;
start = GetCPUTickCount(); array[0]++; end = GetCPUTickCount(); printf("don't use prefetch time:%ld\n", end - start);
for(i = 0; i < MAX_LEN; i++) array[i]++;
prefetchnta(array); start = GetCPUTickCount(); array[0]++; end = GetCPUTickCount(); printf("use prefetch time:%ld\n", end - start);
return 0;}
- cpu时钟预取实例代码分享
- 使用html5 canvas 画时钟代码实例分享
- Android的OkHttp包处理用户认证的代码实例分享
- java随机动态生成汉字验证码图片的实例代码分享
- js获取url参数代码实例分享(JS操作URL)
- js时钟翻牌效果实现代码分享
- c#新手入门级代码分享 using指令与using语句的实例
- 【分享】大量android/iphone软件开发资料和实例代码
- 解读ASP.NET密码强度验证代码实例分享
- java date类与string类实例代码分享
- 基于php&mysql实现聊天室功能的代码实例分享
- Android小人时钟的开发实例分享
- 计算CPU的运算速度和指令平均时钟数实例
- javamail 发送邮件的实例代码分享
- 计算CPU 百分比 - 基于openstack kvm 虚拟机采集片段代码分享
- 分享Android及IOS开源实例代码网址
- html5 canvas js(数字时钟)实例代码
- Java编程几个循环实例代码分享
- java实现的新浪微博分享代码实例