具体要用那个函数?多谢

解决方案 »

  1.   

    运行前后分别GetTickCount()一下,减一下就行了
      

  2.   


    clock_t start, end;
    start = clock();
    your code...
    end = clock();
    time = end - start;
    结果为ms
      

  3.   

    程序的第一个语句写的GetTickCount(),最后一句写的也是这个,可是运行下来总是0。不知道为什么?
      

  4.   

    我用syl08341的方法也总是0,使用GetTickCount()函数的时候还会出现15或16ms,不知道具体因为什么,请各位告之。
      

  5.   

    需要高精度计时用long t=GetTickClock(); 需要更高精度计时可参考下列程序:
      
    #include <windows.h>
    #include <iostream>
    #include <iomanip> 
    using namespace std; 
    int main() 

        LARGE_INTEGER t1,t2,feq; 
        int b=0; 
        QueryPerformanceFrequency(&feq);//每秒跳动次数 
        QueryPerformanceCounter(&t1);//测前跳动次数 
        for(int i=0;i<100;i++) b++; 
        QueryPerformanceCounter(&t2);//测后跳动次数 
        double d=((double)t2.QuadPart-(double)t1.QuadPart)/((double)feq.QuadPart);//时间差秒 
      std::cout<<setprecision(20)<<showpoint<<std::endl;//小数点表示20位 
        std::cout<<d<<std::endl; 
        return 0; 
    }
      

  6.   

    也可以用GetSystemTime来实现啊~
      

  7.   

    为了测试时间,最好让你的程序连续运行N遍,可以测的准确些。
    DWORD a,b;
    a=GetTickCount();
    for(int i=0;i<10000;i++)
    {
           YourFun();
    }
    b=GetTickCount();
    (b-a)/10000就时程序运行的时间单位ms
      

  8.   

    zyoujie你好,为什么要在除以10000呢,是因为循环的次数吗?我现在就是想计算整个循环要用多长时间?两个GetTickCount()函数的差单位是毫秒吗?