网站地图    收藏   

主页 > 前端 > css教程 >

计时器的使用 - html/css语言栏目:html.css - 自学

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] Windows系统下time(),clock(),timeGetTime(),GetTickCount(),QueryPerformanceCounter()来计时 include stdio h include windows h include time h...

 
//Windows系统下time(),clock(),timeGetTime(),GetTickCount(),QueryPerformanceCounter()来计时  
#include <stdio.h>    
#include <windows.h>    
#include <time.h>                   //time_t time()  clock_t clock()    
#include <Mmsystem.h>               //timeGetTime()    
#pragma comment(lib, "Winmm.lib")   //timeGetTime()    
    
//使用方法:将Sleep()函数换成需要测试运行时间的函数即可。  
int main()    
{    
    //用time()来计时  秒    
    time_t timeBegin, timeEnd;    
    timeBegin = time(NULL);    
    Sleep(1000);    
    timeEnd = time(NULL);    
    printf("%d\n", timeEnd - timeBegin);    
        
        
    //用clock()来计时  毫秒    
    clock_t  clockBegin, clockEnd;    
    clockBegin = clock();    
    Sleep(800);    
    clockEnd = clock();    
    printf("%d\n", clockEnd - clockBegin);    
        
        
    //用timeGetTime()来计时  毫秒    
    DWORD  dwBegin, dwEnd;    
    dwBegin = timeGetTime();    
    Sleep(800);    
    dwEnd = timeGetTime();    
    printf("%d\n", dwEnd - dwBegin);    
        
        
    //用GetTickCount()来计时  毫秒    
    DWORD  dwGTCBegin, dwGTCEnd;    
    dwGTCBegin = GetTickCount();    
    Sleep(800);    
    dwGTCEnd = GetTickCount();    
    printf("%d\n", dwGTCEnd - dwGTCBegin);    
        
     
    //用QueryPerformanceCounter()来计时  微秒    
    LARGE_INTEGER  large_interger;    
    double dff;    
    __int64  c1, c2;    
    QueryPerformanceFrequency(&large_interger);    
    dff = large_interger.QuadPart;    
    QueryPerformanceCounter(&large_interger);    
    c1 = large_interger.QuadPart;    
    Sleep(800);    
    QueryPerformanceCounter(&large_interger);    
    c2 = large_interger.QuadPart;    
    printf("本机高精度计时器频率%lf\n", dff);    
    printf("第一次计时器值%I64d 第二次计时器值%I64d 计时器差%I64d\n", c1, c2, c2 - c1);    
    printf("计时%lf毫秒\n", (c2 - c1) * 1000 / dff);    
  
    return 0;    
}    

 
 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论