CPU時間戳計時器

#include <iostream>
#include <ctime>
#include "windows.h"

using namespace std;

double GetCPUFreq()
{
    int start1, start2;
    _asm rdtsc
    _asm mov start1, eax
    Sleep(100);
    _asm rdtsc
    _asm mov start2, eax
    return (double(start2 - start1) / 100) / (1000*1000);
}

inline __int64 GetCycleCount()
{
__asm _emit 0x0F
__asm _emit 0x31
}
int main()
{
    int a; 
    __int64 t;
    auto freq = GetCPUFreq();
    cout << freq << "GHZ";
    system("pause");
    t = GetCycleCount();
    do
    {
        system("cls");
        cout << (GetCycleCount() - t)/(1000*1000*1000*freq);
    } while (1);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章