cpu時鐘預取實例代碼分享
測試下預取的效果,利用CPU始終查看效果。根據(jù)實驗發(fā)現(xiàn),預取地址在地址使用之前的十行左右代碼處效果比較好!
#include <stdio.h>
#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;
}
相關(guān)文章
Linux文本查看命令及其選項詳解(cat,head,tail)
這篇文章主要介紹了Linux文本查看命令及其選項詳解(cat,head,tail),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08linux數(shù)據(jù)庫備份并通過ftp上傳腳本分享
這篇文章主要介紹了linux數(shù)據(jù)庫備份并通過ftp上傳腳本,腳本還可以備份網(wǎng)站,需要的朋友可以參考下2014-03-03shell腳本實現(xiàn)公司項目部署交付環(huán)境預檢查的思路
這篇文章主要介紹了shell腳本實現(xiàn)公司項目部署交付環(huán)境預檢查的思路,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09統(tǒng)計網(wǎng)卡流量的兩段shell腳本(使用ifconfig)
一個很小巧的shell腳本,使用ifconfig的不間斷輸出來統(tǒng)計網(wǎng)卡的流量,有需要的朋友可以參考下2013-02-02shell腳本聯(lián)合PHP腳本采集網(wǎng)站的pv和alexa排名
這篇文章主要介紹了shell腳本聯(lián)合PHP腳本采集網(wǎng)站的pv和alexa排名,本文使用PHP腳本采集alexa網(wǎng)站數(shù)據(jù),然后在shell中調(diào)用php腳本并輸出數(shù)據(jù),需要的朋友可以參考下2014-12-12