正文

强制CPU开始新的周期的方法2008-09-18 01:02:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/38333.html

分享到:

#include <afx.h>
#include <stdio.h>

void GetCylc( unsigned int *lowPart, unsigned int *highPart )
{
    __asm {
        cpuid         // 强制CPU开始新的周期
        mov ecx, lowPart;
        mov ebx, highPart;
        rdtsc
        mov [ecx], eax;
        mov [ebx], edx;
    }
}

unsigned int lowPart1, lowPart2, highPart;

int main()
{
    char *s1 = "2o3i4jiojrewjeroiksopf";

    GetCylc( &lowPart1, &highPart );

    for(int i1=0;s1[i1]!=0;i1++)
        printf("%c",s1[i1]);
    printf("\n");

    CString s2 = "2o3i4jiojrewjeroiksopf";
    for(int i2=0;i2<s2.GetLength();i2++)
        printf("%c",s2[i2]); // s2.GetAt(i2)
    printf("\n");
    GetCylc( &lowPart2, &highPart );
    printf("finish time = lowPart2 - lowPart1 = %d\n",lowPart2 - lowPart1);
    getchar();
    return 0;
}


阅读(3514) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册