計(jì)算程序時(shí)間的方法

字號(hào):

void time_one()
    {
    LARGE_INTEGER one;
    LARGE_INTEGER two;
    LARGE_INTEGER freq;
    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&one);
    for (int i = 0; i < 1000000000; i++)
    {
    }
    QueryPerformanceCounter(&two);
    cout << two.QuadPart * 1.0 / freq.QuadPart - one.QuadPart * 1.0 / freq.QuadPart << endl;
    }
    void time_two()
    {
    double timeStart = GetTickCount();
    for (int i = 0; i < 10000000; i++)
    {
    }
    double timeEnd = GetTickCount();
    cout << timeEnd - timeStart << endl;
    }
    void time_three()
    {
    time_t stime;
    time_t etime;
    time(&stime);
    getchar();
    time(&etime);
    printf(\"%ld\\n\",etime - stime);
    }
    void time_four()
    {
    double begin=(double)clock()/CLK_TCK;
    for (int i = 0; i < 1000000000; i++)
    {
    }
     double end=(double)clock()/CLK_TCK;
     cout << end - begin << endl;
    }
    void time_five()
    {
     clock_t t1 = clock();
     for (int i = 0; i < 1000000000; i++)
    {
    }
     clock_t t2 = clock();
     cout<<\"Total time = \"<    }