- 注册时间
- 2008-2-6
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 51573
- 在线时间
- 小时
|
发表于 2008-3-11 09:26:38
|
显示全部楼层
/*
yaos: 3.146
CPU Clock Used: 1064
GXQ: 2.896
CPU Clock Used: 700
*/
#include
#include
#include
__int64 GetCPUCounter(void)
{
__asm rdtsc;
}
void find_by_yaos(DWORD a, DWORD index[33])
{
__asm
{
mov edx, a;
mov edi, dword ptr index;
xor eax, eax;
loop1:
bsr ecx, edx;
je exit1;
btr edx, ecx;
mov dword ptr [edi + 4*eax], ecx;
inc eax;
jmp loop1;
exit1:
mov dword ptr [edi + 4*eax], -1;
}
}
DWORD find_by_GxQ(DWORD code, DWORD index[33])
{
__asm
{
mov ecx, code;
xor eax, eax;
shr ecx, 1;
mov dword ptr[index + 4*eax], 0;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 1;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 2;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 3;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 4;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 5;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 6;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 7;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 8;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 9;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 10;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 11;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 12;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 13;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 14;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 15;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 16;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 17;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 18;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 19;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 20;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 21;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 22;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 23;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 24;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 25;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 26;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 27;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 28;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 29;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 30;
adc eax, 0;
shr ecx, 1;
mov dword ptr[index + 4*eax], 31;
adc eax, 0;
// 休止符
mov dword ptr[index + 4*eax], -1;
}
}
int main(int argc, char * argv[])
{
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
LARGE_INTEGER lTimestart, lTimeEnd, liFreq;
__int64 CounterStart, CounterStop;
DWORD index[33];
QueryPerformanceCounter(&lTimestart);
for(DWORD i = 0; i <= 0x1000000; i++){
find_by_yaos(i, index);// 调用bit扫描函数
}
CounterStart = GetCPUCounter();
find_by_yaos(0xFFFFFFFF, index);
CounterStop = GetCPUCounter();
QueryPerformanceCounter(&lTimeEnd);
QueryPerformanceFrequency(&liFreq);
double dbMs = ((double) (lTimeEnd.QuadPart - lTimestart.QuadPart)) / (double)liFreq.QuadPart;
printf("yaos: %.3f\n", dbMs);
printf(" CPU Clock Used: %ld\n", CounterStop - CounterStart);
QueryPerformanceCounter(&lTimestart);
for(DWORD i = 0; i <= 0x1000000; i++){
find_by_GxQ(i, index);// 调用bit扫描函数
}
CounterStart = GetCPUCounter();
find_by_GxQ(0xFFFFFFFF, index);
CounterStop = GetCPUCounter();
QueryPerformanceCounter(&lTimeEnd);
QueryPerformanceFrequency(&liFreq);
dbMs = ((double) (lTimeEnd.QuadPart - lTimestart.QuadPart)) / (double)liFreq.QuadPart;
printf("GXQ: %.3f\n", dbMs);
printf(" CPU Clock Used: %ld\n", CounterStop - CounterStart);
//system("Pause");
return 0;
} |
|